2

I am making a form and would like to use a ToolStripDropDownButton (basically a button with an arrow pointing down from where u can select an item):

as found in the Microsoft website but I cannot seem to find it in the form[design] toolbox.

I am using VS2015 C# community version, net framework 4.6. I have tried adding the namespace using System.Windows.Forms.ToolStripDropDownButton; but it does not recognize toolstripdropdownbutton. Any help with this would be appreciated. Thanks.

ivamax9
  • 2,601
  • 24
  • 33
metaplexer
  • 55
  • 6
  • `System.Windows.Forms.ToolStripDropDownButton` is a class, is not a namespace. – Reza Aghaei Nov 20 '15 at 10:02
  • I see, thanks. My mistake. Any idea how I can use that class to create the toolstripdropdownbutton control? So far, I have only used controls that I can drag and drop from the design toolbox. Maybe pointing me out on the right direction? I found this: https://msdn.microsoft.com/en-us/library/x5cbt5y9(v=vs.110).aspx where they show how initialize this control, but do not where they do it. I have tried it but nothing happens in my form. – metaplexer Nov 20 '15 at 10:05
  • I posted an answer for you. Let me know if you have any question about the answer. – Reza Aghaei Nov 20 '15 at 10:23

1 Answers1

2

The problem in your code is because System.Windows.Forms.ToolStripDropDownButton is a class, is not a namespace.

Any idea how I can use that class to create the toolstripdropdownbutton control?

Using Code:

var item = new ToolStripDropDownButton("SomeText");
item.DropDownItems.Add(new ToolStripMenuItem("SubMenu1"));
item.DropDownItems.Add(new ToolStripMenuItem("SubMenu1"));
this.toolStrip1.Items.Add(item); 

You can also take a look at below constructor to add an image and an event handler and see more example at bottom of documentation page:

Result:

enter image description here

Using the designer:

You can put a ToolStrip on form, then click the dropdown of add item. then select DropDownButton.

enter image description here

More information:

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • Thanks a lot! This is what I needed. Your screenshots made me realize that when I was trying to use toolstrip earlier I was not able to see the controls on the upper left because a panel was sitting on top of it... Your explanation was very clear and answered my question. I appreciate the effort you put into it, I have marked it as the answer. Thanks again! – metaplexer Nov 20 '15 at 10:28