.netwinformscontextmenustriptoolstripbutton

ToolStripButton text gets cut off in ContextMenuStrip


I am instantiating my own ToolStripButton and adding it to a ContextMenuStrip. It pops up but the text gets cut off:

string[] layouts = new string[]{"Test 1", "Test 2", "Test 3"};
List<ToolStripButton> items = new List<ToolStripButton>();
foreach (string layout in layouts)
{
    ToolStripButton item = new ToolStripButton(layout, image, LayoutClicked);
    item.AutoSize = true;
    items.Add(item);
}
layoutMenus.Items.Clear();
layoutMenus.Items.AddRange(items.ToArray());
layoutMenus.Show(Cursor.Position.X, Cursor.Position.Y);

Any idea why the text is getting cut off as the AutoSize property is true?


Solution

  • Curious; I can reproduce this... a reall oddity (for me) is that setting the menu's .Width fixes it... but setting it to anything (it seems to ignore the value completely):

    layoutMenus.Width = 800; // could be 20, or 100 and would appear the same
    

    See if that works. It does for me, even though it makes no real sense.

    Even:

    layoutMenus.Width++;
    layoutMenus.Width--;
    

    leaves enough space, but

    layoutMenus.Width = layoutMenus.Width;
    

    doesn't (presumably it checks for non-changes and ignores whatever side-effects the above has).