Skip to content

Commit 6c7abd1

Browse files
committed
Update OnSelectedItemName_Paint: When selectedItem.Site is null, only show selectedItem type in Items Collection Editor
1 parent 98322e5 commit 6c7abd1

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripCollectionEditor.ToolStripItemEditorForm.cs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,8 @@ private void OnNewItemTypes_SelectionChangeCommitted(object sender, EventArgs e)
590590
{
591591
if (ex.IsCriticalException())
592592
{
593-
throw;
594-
}
593+
throw;
594+
}
595595
}
596596

597597
PropertyDescriptor imageProperty = TypeDescriptor.GetProperties(newItem)[nameof(Image)];
@@ -885,33 +885,30 @@ private void OnSelectedItemName_Paint(object sender, PaintEventArgs e)
885885
selectedItem = _listBoxItems.SelectedItem is ToolStrip strip ? strip : (ToolStripItem)_listBoxItems.SelectedItem;
886886

887887
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;
898891

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+
}
905896

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;
911903

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;
913908
}
914909

910+
TextRenderer.DrawText(e.Graphics, itemName, _selectedItemName.Font, textRect, SystemColors.WindowText, flags);
911+
915912
break;
916913
case 0:
917914
// Erase background.

0 commit comments

Comments
 (0)