Search code examples
c#parenttoolstripbutton

How to set the Control.Parent proprety in C#


I'm making a plugin parser for my C# web browser.

When making the button for the plugin, I need to add the ToolStripButton to the ToolStrip.

Here's my code:

ToolStripButton pluginButton = new ToolStripButton();
pluginButton.Parent = toolStrip1;
pluginButton.Image = Simple_Browse.Properties.Resources.plugin;
pluginButton.Alignment = ToolStripItemAlignment.Left;
pluginButton.ToolTipText = TitlePlugin;

I get an error on line 2:
System.Windows.ToolStripItem.Parent is inaccessible due to its permission level.

I've looked it up on Microsoft on how to set it. It says .NET Protection somewhere. I studied that and it makes NO sense.


Solution

  • Rather than setting pluginButton.Parent = toolStrip1, use toolStrip1.Items.Add( pluginButton ) instead.