4
4
using DrawnTableControl . Services ;
5
5
using System ;
6
6
using System . Collections . Generic ;
7
+ using System . Diagnostics . CodeAnalysis ;
7
8
using System . Drawing ;
8
9
using System . Drawing . Drawing2D ;
9
10
using System . Linq ;
@@ -41,7 +42,7 @@ public bool AllowDragDrop
41
42
private DrawnTableOverlapOptions ifCellsOverlap = DrawnTableOverlapOptions . ThrowError ;
42
43
/// <summary>
43
44
/// Attention! This option allow cell to be overlapped by another cell been added via AddCell method only.
44
- /// If option "Hide" is chosen, once cells overlapped each other they got removed from table and basicly became impossible to interact with.
45
+ /// If option "Hide" is chosen, once cells overlapped each other they got removed from table and basically became impossible to interact with.
45
46
/// If option "Merge" is chosen, once cells overlapped each other their values need to be merged manually by CellsMerging event.
46
47
/// </summary>
47
48
public DrawnTableOverlapOptions IfCellsOverlap
@@ -92,6 +93,7 @@ public DrawnTableCopyMode CellCopyMode
92
93
}
93
94
94
95
// Table information
96
+ [ MemberNotNullWhen ( true , nameof ( table ) ) ]
95
97
public bool IsEnabled { get ; private set ; } = false ;
96
98
public RectangleF CellsArea { get ; private set ; }
97
99
public RectangleF TableArea { get ; private set ; }
@@ -116,7 +118,7 @@ public Color BorderColor
116
118
public DrawnTableCells Cells { get ; private set ; }
117
119
//public int CellMargin { get; set; } = 2;
118
120
119
- internal Bitmap table { get ; private set ; }
121
+ internal Bitmap ? table { get ; private set ; }
120
122
121
123
private readonly PBDrawnTable Owner ;
122
124
internal DeferredExecution dRedrawEx ;
@@ -126,52 +128,25 @@ public Color BorderColor
126
128
#endregion
127
129
128
130
#region Events
129
- public event EventHandler < CellMovedEventArgs > CellDragOver ;
130
- public event EventHandler < CellMovedEventArgs > CellDragDropFinished ;
131
- public event EventHandler < CellClickEventArgs > CellWithValueClick ;
132
- public event EventHandler < CellChangedEventArgs > CellCreated ;
133
- public event EventHandler < CellChangedEventArgs > CellCreating ;
134
- public event EventHandler < CellOverlapEventArgs > CellOverlapPlaceholderClick ;
135
- public event EventHandler < CellsMergingEventArgs > CellsMerging ;
136
- public event EventHandler < CellCopiedEventArgs > CellCopied ;
137
- public event EventHandler < CellPastedEventArgs > CellPasted ;
138
-
139
- internal virtual void OnCellDragOver ( CellMovedEventArgs e )
140
- {
141
- CellDragOver ? . Invoke ( this , e ) ;
142
- }
143
- internal virtual void OnCellDragDropFinished ( CellMovedEventArgs e )
144
- {
145
- CellDragDropFinished ? . Invoke ( this , e ) ;
146
- }
147
- internal virtual void OnCellWithValueClick ( CellClickEventArgs e )
148
- {
149
- CellWithValueClick ? . Invoke ( this , e ) ;
150
- }
151
- internal virtual void OnCellCreating ( CellChangedEventArgs e )
152
- {
153
- CellCreating ? . Invoke ( this , e ) ;
154
- }
155
- internal virtual void OnCellCreated ( CellChangedEventArgs e )
156
- {
157
- CellCreated ? . Invoke ( this , e ) ;
158
- }
159
- internal virtual void OnCellOverlapPlaceholderClick ( CellOverlapEventArgs e )
160
- {
161
- CellOverlapPlaceholderClick ? . Invoke ( this , e ) ;
162
- }
163
- internal virtual void OnCellsMerging ( CellsMergingEventArgs e )
164
- {
165
- CellsMerging ? . Invoke ( this , e ) ;
166
- }
167
- internal virtual void OnCellCopied ( CellCopiedEventArgs e )
168
- {
169
- CellCopied ? . Invoke ( this , e ) ;
170
- }
171
- internal virtual void OnCellPasted ( CellPastedEventArgs e )
172
- {
173
- CellPasted ? . Invoke ( this , e ) ;
174
- }
131
+ public event EventHandler < CellMovedEventArgs > ? CellDragOver ;
132
+ public event EventHandler < CellMovedEventArgs > ? CellDragDropFinished ;
133
+ public event EventHandler < CellClickEventArgs > ? CellWithValueClick ;
134
+ public event EventHandler < CellChangedEventArgs > ? CellCreated ;
135
+ public event EventHandler < CellChangedEventArgs > ? CellCreating ;
136
+ public event EventHandler < CellOverlapEventArgs > ? CellOverlapPlaceholderClick ;
137
+ public event EventHandler < CellsMergingEventArgs > ? CellsMerging ;
138
+ public event EventHandler < CellCopiedEventArgs > ? CellCopied ;
139
+ public event EventHandler < CellPastedEventArgs > ? CellPasted ;
140
+
141
+ internal virtual void OnCellDragOver ( CellMovedEventArgs e ) => CellDragOver ? . Invoke ( this , e ) ;
142
+ internal virtual void OnCellDragDropFinished ( CellMovedEventArgs e ) => CellDragDropFinished ? . Invoke ( this , e ) ;
143
+ internal virtual void OnCellWithValueClick ( CellClickEventArgs e ) => CellWithValueClick ? . Invoke ( this , e ) ;
144
+ internal virtual void OnCellCreating ( CellChangedEventArgs e ) => CellCreating ? . Invoke ( this , e ) ;
145
+ internal virtual void OnCellCreated ( CellChangedEventArgs e ) => CellCreated ? . Invoke ( this , e ) ;
146
+ internal virtual void OnCellOverlapPlaceholderClick ( CellOverlapEventArgs e ) => CellOverlapPlaceholderClick ? . Invoke ( this , e ) ;
147
+ internal virtual void OnCellsMerging ( CellsMergingEventArgs e ) => CellsMerging ? . Invoke ( this , e ) ;
148
+ internal virtual void OnCellCopied ( CellCopiedEventArgs e ) => CellCopied ? . Invoke ( this , e ) ;
149
+ internal virtual void OnCellPasted ( CellPastedEventArgs e ) => CellPasted ? . Invoke ( this , e ) ;
175
150
#endregion
176
151
177
152
internal DrawnTable ( PBDrawnTable owner )
@@ -203,7 +178,7 @@ public void Create(List<DrawnTableHeader> rows, List<DrawnTableHeader> cols)
203
178
public void Remove ( )
204
179
{
205
180
IsEnabled = false ;
206
- Cells = null ;
181
+ Cells = new DrawnTableCells ( this ) ;
207
182
table ? . Dispose ( ) ;
208
183
table = null ;
209
184
Owner . mouseDown = false ;
@@ -224,16 +199,10 @@ public void Remove()
224
199
CellPasted = null ;
225
200
}
226
201
227
- private RectangleF GetDefaultArea ( )
228
- {
229
- return new RectangleF ( 0 , 0 , Owner . Width , Owner . Height ) ;
230
- }
202
+ private RectangleF GetDefaultArea ( ) => new ( 0 , 0 , Owner . Width , Owner . Height ) ;
231
203
232
204
internal void Resize ( ) => Resize ( GetDefaultArea ( ) ) ;
233
- internal void Resize ( RectangleF newTableArea )
234
- {
235
- dRedrawEx . Execute ( ( ) => ActualRedraw ( newTableArea ) ) ;
236
- }
205
+ internal void Resize ( RectangleF newTableArea ) => dRedrawEx . Execute ( ( ) => ActualRedraw ( newTableArea ) ) ;
237
206
238
207
public Font GetDefaultFont ( )
239
208
{
@@ -260,10 +229,7 @@ internal static Graphics GetGraphics(Image image)
260
229
return graphics ;
261
230
}
262
231
263
- public void Redraw ( )
264
- {
265
- dRedrawEx . Execute ( ( ) => ActualRedraw ( ) ) ;
266
- }
232
+ public void Redraw ( ) => dRedrawEx . Execute ( ( ) => ActualRedraw ( ) ) ;
267
233
268
234
private void ActualRedraw ( RectangleF area = default )
269
235
{
@@ -305,7 +271,7 @@ internal void ActualRedraw(Graphics g, RectangleF area)
305
271
g . DrawImage ( table , TableArea ) ;
306
272
307
273
// Coping cells and back colors to draw them in the separate thread
308
- Dictionary < DrawnTableCell , RectangleF > currCells = null ;
274
+ Dictionary < DrawnTableCell , RectangleF > currCells = null ! ;
309
275
Owner . Invoke ( new Action ( ( ) =>
310
276
{
311
277
currCells = Cells . Select ( c => ( DrawnTableCell ) c . Clone ( true ) ) . ToDictionary ( x => x , i => RectangleF . Empty ) ;
@@ -374,10 +340,7 @@ private Bitmap RedrawBackground()
374
340
375
341
private void DrawTable ( Graphics g , SizeF size , List < DrawnTableHeader > cols , List < DrawnTableHeader > rows , Font font )
376
342
{
377
- if ( cols . Count == 0 || rows . Count == 0 )
378
- {
379
- return ;
380
- }
343
+ if ( cols . Count == 0 || rows . Count == 0 ) return ;
381
344
382
345
const int div = 1 ;
383
346
float colHeaderH = cols . Max ( c => TextRenderer . MeasureText ( c . Text , font ) . Height ) ;
@@ -475,7 +438,7 @@ private void DrawTable(Graphics g, SizeF size, List<DrawnTableHeader> cols, List
475
438
RowHeight = rowH ;
476
439
}
477
440
478
- internal RectangleF DrawCell ( DrawnTableCell cell , Graphics g = null )
441
+ internal RectangleF DrawCell ( DrawnTableCell cell , Graphics ? g = null )
479
442
{
480
443
RectangleF cellArea = GetCellArea ( cell . Location ) ;
481
444
if ( cell . Rowspan != 1 )
@@ -492,7 +455,8 @@ internal RectangleF DrawCell(DrawnTableCell cell, Graphics g = null)
492
455
493
456
return res ;
494
457
}
495
- internal static RectangleF DrawCell ( string text , Font font , Brush brush , RectangleF area , StringFormat format = null , Graphics g = null )
458
+
459
+ internal static RectangleF DrawCell ( string ? text , Font font , Brush brush , RectangleF area , StringFormat ? format = null , Graphics ? g = null )
496
460
{
497
461
const int padding = 2 ;
498
462
@@ -624,10 +588,7 @@ private static int CountHeaders(IEnumerable<DrawnTableHeader> headers)
624
588
return headerCount ;
625
589
}
626
590
627
- public void SuspendRedrawing ( )
628
- {
629
- isRedrawingSuspended = true ;
630
- }
591
+ public void SuspendRedrawing ( ) => isRedrawingSuspended = true ;
631
592
632
593
public void ResumeRedrawing ( )
633
594
{
0 commit comments