I need to add a set of custom ToolStripItem
(containing the additional property formReference
) to a ToolStripPanel
but they won't appear for some reason.
Code for adding the items:
foreach (Form form in Application.OpenForms)
if (form.Name != "MainForm")
{
myToolStripItem mtsi = new myToolStripItem(form.Text, null, open_form);
mtsi.formReference = form;
tspTaskBar.Items.Add(mtsi);
}
myToo开发者_高级运维lStripItem:
public class myToolStripItem : ToolStripItem
{
public object formReference { get; set; }
public myToolStripItem(string text, System.Drawing.Image image, EventHandler onClick)
: base(text,image,onClick) { }
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
}
Can you please point me to what I'm doing wrong? Thank you.
Deriving from ToolStripMenuItem
instead of ToolStripItem
solved it
I think the problem might be that ToolStripPanel
is a panel for ToolStrip
s and a ToolStrip
is the actual place where you put ToolStripItems
. Try putting a ToolStrip
inside your ToolStripPanel
and putting your custom ToolStripItem
into that ToolStrip
.
精彩评论