jorne
jorne

Reputation: 903

filling a toolStripDropDownButton

what i'm basicaly wan to do, is add somme items in a toolstripdropdownbutton. What i did was:

toolStripDropDownButtonColor.DropDownItems.Add("text", null, ChangeTextColor);

But now i need to change the fore en the back color of those items, so i saw that i can use ToolStripItem. And here i can set the propertys i want to,

But: How do i declare sommething like that? i have sommething like this:

ToolStripItem fs;
  fs.Text = c.ToString();
  fs.ForeColor = System.Drawing.Color.FromKnownColor(c);
  fs.BackColor = System.Drawing.Color.FromKnownColor(c);
  fs.Click += ChangeTextColor;

  toolStripDropDownButtonColor.DropDownItems.Add(fs);

Upvotes: 2

Views: 2288

Answers (1)

Thaven
Thaven

Reputation: 1897

ToolStripItem is abstract class, so You can't declare object of this class. In this case, You can use ToolStripMenuItem instead:

  ToolStripItem fs = new ToolStripMenuItem();
  fs.Text = c.ToString();
  fs.ForeColor = System.Drawing.Color.FromKnownColor(c);
  fs.BackColor = System.Drawing.Color.FromKnownColor(c);
  fs.Click += ChangeTextColor;

  toolStripDropDownButtonColor.DropDownItems.Add(fs);

Upvotes: 2

Related Questions