@@ -34,7 +34,6 @@ public class MaterialListBox : Control, MaterialControlI
34
34
private int _selectedIndex ;
35
35
private MaterialListBoxItem _selectedItem ;
36
36
private bool _showScrollBar ;
37
- private bool _multiKeyDown ;
38
37
private int _hoveredItem ;
39
38
private MaterialScrollBar _scrollBar ;
40
39
private bool _smoothScrolling = true ;
@@ -291,7 +290,6 @@ private void SetDefaults()
291
290
Items . CollectionChanged += InvalidateScroll ;
292
291
SelectedItems = new List < object > ( ) ;
293
292
_indicates = new List < object > ( ) ;
294
- _multiKeyDown = false ;
295
293
_scrollBar = new MaterialScrollBar ( )
296
294
{
297
295
Orientation = MateScrollOrientation . Vertical ,
@@ -403,15 +401,14 @@ protected override void OnPaint(PaintEventArgs e)
403
401
int itemOffset = SmoothScrolling ? _scrollBar . Value - ( firstItem * _itemHeight ) : 0 ;
404
402
405
403
// Calculate the last item
406
- int lastItem = ( _scrollBar . Value / _itemHeight ) + ( ( Height + itemOffset ) / _itemHeight ) + 1 > Items . Count ?
407
- Items . Count :
408
- ( _scrollBar . Value / _itemHeight ) + ( ( Height + itemOffset ) / _itemHeight ) + 1 ;
404
+ int lastItem = ( _scrollBar . Value / _itemHeight ) + ( ( Height + itemOffset ) / _itemHeight ) + 1 > Items . Count ? Items . Count : ( _scrollBar . Value / _itemHeight ) + ( ( Height + itemOffset ) / _itemHeight ) + 1 ;
409
405
410
406
g . FillRectangle ( Enabled ? SkinManager . BackgroundBrush : SkinManager . BackgroundDisabledBrush , mainRect ) ;
411
407
412
408
//Set TextAlignFlags
413
409
MaterialNativeTextRenderer . TextAlignFlags primaryTextAlignFlags ;
414
410
MaterialNativeTextRenderer . TextAlignFlags secondaryTextAlignFlags = MaterialNativeTextRenderer . TextAlignFlags . Left | MaterialNativeTextRenderer . TextAlignFlags . Top ;
411
+
415
412
if ( _style is ListBoxStyle . TwoLine or ListBoxStyle . ThreeLine )
416
413
{
417
414
primaryTextAlignFlags = MaterialNativeTextRenderer . TextAlignFlags . Left | MaterialNativeTextRenderer . TextAlignFlags . Bottom ;
@@ -451,10 +448,7 @@ protected override void OnPaint(PaintEventArgs e)
451
448
}
452
449
else if ( _indicates . Contains ( i ) )
453
450
{
454
- g . FillRectangle ( Enabled ?
455
- SelectedBrush :
456
- new SolidBrush ( BlendColor ( SelectedColor , SkinManager . SwitchOffDisabledThumbColor , 197 ) ) ,
457
- itemRect ) ;
451
+ g . FillRectangle ( Enabled ? SelectedBrush : new SolidBrush ( BlendColor ( SelectedColor , SkinManager . SwitchOffDisabledThumbColor , 197 ) ) , itemRect ) ;
458
452
}
459
453
}
460
454
else
@@ -465,10 +459,7 @@ protected override void OnPaint(PaintEventArgs e)
465
459
}
466
460
else if ( i == SelectedIndex )
467
461
{
468
- g . FillRectangle ( Enabled ?
469
- SelectedBrush :
470
- new SolidBrush ( BlendColor ( SelectedColor , SkinManager . SwitchOffDisabledThumbColor , 197 ) ) ,
471
- itemRect ) ;
462
+ g . FillRectangle ( Enabled ? SelectedBrush : new SolidBrush ( BlendColor ( SelectedColor , SkinManager . SwitchOffDisabledThumbColor , 197 ) ) , itemRect ) ;
472
463
}
473
464
}
474
465
@@ -497,7 +488,7 @@ protected override void OnPaint(PaintEventArgs e)
497
488
NativeText . DrawTransparentText (
498
489
itemText ,
499
490
_primaryFont ,
500
- Enabled ? ( i != SelectedIndex || UseAccentColor ) ?
491
+ Enabled ? ( ( i != SelectedIndex && ! _indicates . Contains ( i ) ) || UseAccentColor ) ?
501
492
SkinManager . TextHighEmphasisColor :
502
493
SkinManager . ColorScheme . TextColor :
503
494
SkinManager . TextDisabledOrHintColor , // Disabled
@@ -733,10 +724,25 @@ protected override void OnMouseDown(MouseEventArgs e)
733
724
734
725
if ( index >= 0 && index < Items . Count )
735
726
{
736
- if ( MultiSelect && _multiKeyDown )
727
+ if ( MultiSelect && ( ModifierKeys == Keys . Control || ModifierKeys == Keys . Shift ) )
737
728
{
729
+ if ( SelectedIndex >= 0 )
730
+ {
731
+ if ( ! _indicates . Contains ( SelectedIndex ) )
732
+ {
733
+ _indicates . Add ( SelectedIndex ) ;
734
+ }
735
+ if ( ! SelectedItems . Contains ( Items [ SelectedIndex ] ) )
736
+ {
737
+ SelectedItems . Add ( Items [ SelectedIndex ] ) ;
738
+ }
739
+
740
+ SelectedIndex = - 1 ;
741
+ }
742
+
738
743
_indicates . Add ( index ) ;
739
744
SelectedItems . Add ( Items [ index ] ) ;
745
+ SelectedValueChanged ? . Invoke ( this , Items [ index ] ) ;
740
746
}
741
747
else
742
748
{
0 commit comments