开发者

Custom ToolStripItem

开发者 https://www.devze.com 2023-01-27 10:24 出处:网络
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.

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 ToolStrips 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消