@@ -590,8 +590,8 @@ private void OnNewItemTypes_SelectionChangeCommitted(object sender, EventArgs e)
590
590
{
591
591
if ( ex . IsCriticalException ( ) )
592
592
{
593
- throw ;
594
- }
593
+ throw ;
594
+ }
595
595
}
596
596
597
597
PropertyDescriptor imageProperty = TypeDescriptor . GetProperties ( newItem ) [ nameof ( Image ) ] ;
@@ -885,33 +885,30 @@ private void OnSelectedItemName_Paint(object sender, PaintEventArgs e)
885
885
selectedItem = _listBoxItems . SelectedItem is ToolStrip strip ? strip : ( ToolStripItem ) _listBoxItems . SelectedItem ;
886
886
887
887
string className = "&" + selectedItem . GetType ( ) . Name ;
888
- if ( selectedItem . Site is not null )
889
- {
890
- // Erase background
891
- e . Graphics . FillRectangle ( SystemBrushes . Control , bounds ) ;
892
- string itemName = selectedItem . Site . Name ;
893
-
894
- if ( label is not null )
895
- {
896
- label . Text = className + itemName ;
897
- }
888
+ // Erase background
889
+ e . Graphics . FillRectangle ( SystemBrushes . Control , bounds ) ;
890
+ string itemName = selectedItem . Site ? . Name ?? string . Empty ;
898
891
899
- int classWidth = 0 ;
900
- classWidth = ( int ) e . Graphics . MeasureString ( className , boldFont ) . Width ;
901
- e . Graphics . DrawString ( className , boldFont , SystemBrushes . WindowText , bounds , stringFormat ) ;
902
- int itemTextWidth = ( int ) e . Graphics . MeasureString ( itemName , _selectedItemName . Font ) . Width ;
903
- Rectangle textRect = new ( classWidth + GdiPlusExtraSpace , 0 , bounds . Width - ( classWidth + GdiPlusExtraSpace ) , bounds . Height ) ;
904
- label . AutoEllipsis = itemTextWidth > textRect . Width ;
892
+ if ( label is not null )
893
+ {
894
+ label . Text = className + itemName ;
895
+ }
905
896
906
- TextFormatFlags flags = TextFormatFlags . EndEllipsis | TextFormatFlags . PreserveGraphicsTranslateTransform | TextFormatFlags . PreserveGraphicsClipping ;
907
- if ( rightToLeft )
908
- {
909
- flags |= TextFormatFlags . RightToLeft ;
910
- }
897
+ int classWidth = 0 ;
898
+ classWidth = ( int ) e . Graphics . MeasureString ( className , boldFont ) . Width ;
899
+ e . Graphics . DrawString ( className , boldFont , SystemBrushes . WindowText , bounds , stringFormat ) ;
900
+ int itemTextWidth = ( int ) e . Graphics . MeasureString ( itemName , _selectedItemName . Font ) . Width ;
901
+ Rectangle textRect = new ( classWidth + GdiPlusExtraSpace , 0 , bounds . Width - ( classWidth + GdiPlusExtraSpace ) , bounds . Height ) ;
902
+ label . AutoEllipsis = itemTextWidth > textRect . Width ;
911
903
912
- TextRenderer . DrawText ( e . Graphics , itemName , _selectedItemName . Font , textRect , SystemColors . WindowText , flags ) ;
904
+ TextFormatFlags flags = TextFormatFlags . EndEllipsis | TextFormatFlags . PreserveGraphicsTranslateTransform | TextFormatFlags . PreserveGraphicsClipping ;
905
+ if ( rightToLeft )
906
+ {
907
+ flags |= TextFormatFlags . RightToLeft ;
913
908
}
914
909
910
+ TextRenderer . DrawText ( e . Graphics , itemName , _selectedItemName . Font , textRect , SystemColors . WindowText , flags ) ;
911
+
915
912
break ;
916
913
case 0 :
917
914
// Erase background.
0 commit comments