Dynamic Menustrip

  • Thread starter Thread starter =?ISO-8859-1?Q?J=FCrgen_Roos?=
  • Start date Start date
?

=?ISO-8859-1?Q?J=FCrgen_Roos?=

Hello,
Why does this code not work? The result is an empty entry in the menu
viewing the debugger I see that the property visible is false. I tried
to make visible=true but it still remains false. And for my
understanding why is an entry with visible=false visible with an empty
string despite the property text is filled well?

public class MyMenuItem : ToolStripItem
{
public MyMenuItem(string Name)
{
this.Name = Name;
}
}

private void AddMenuItems()
{
string[] items = { "MenuItem1", "MenuItem2" };
toolStripMenuItem1.DropDownItems.Clear();

foreach (string item in items)
{
MyMenuItem mmi = new MyMenuItem(item);
mmi.Text = item;
//mmi.Click += new EventHandler(mmi_Click);

toolStripMenuItem1.DropDownItems.Add(mmi);
}
}
 
Jürgen Roos said:
Hello,
Why does this code not work? The result is an empty entry in the menu
viewing the debugger I see that the property visible is false. I tried
to make visible=true but it still remains false. And for my
understanding why is an entry with visible=false visible with an empty
string despite the property text is filled well?

public class MyMenuItem : ToolStripItem

ToolStripItem is the abstract base class of all the items that can
possibly appear in ToolStrips, and so doesn't have any built in painting
logic. If you want to derive directly from ToolStripItem, it's up to you
to override OnPaint and provide your desired painting behaviour in there
- otherwise (as you have found), nothing gets painted.

If you're happy with, say, the painting of a ToolStripMenuItem, then
just derive from that.
 
Back
Top