2

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);
}

myToolStripItem:

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.

Zach Johnson
  • 23,678
  • 6
  • 69
  • 86
francis
  • 700
  • 2
  • 7
  • 18

2 Answers2

2

Deriving from ToolStripMenuItem instead of ToolStripItem solved it

francis
  • 700
  • 2
  • 7
  • 18
0

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.

Zach Johnson
  • 23,678
  • 6
  • 69
  • 86
  • i'm sorry, i said toolStripPanel but what i have is a ToolStrip (tspTaskBar is a ToolStrip, not a toolStripPanel). The tspTaskBar.Items.Add() method accepts a ToolStripItem as an argument so i'm pretty sure you add ToolStripItems to the Items collection. – francis Dec 02 '10 at 09:28