我正在制作一个表单,并希望使用 ToolStripDropDownButton
(基本上是一个带有向下箭头的按钮,您可以从此处选择一个项目):
as found in the Microsoft website但我似乎无法在表单[设计]工具箱中找到它。
我使用的是VS2015 C#社区版,net Framework 4.6。我尝试添加命名空间using System.Windows.Forms.ToolStripDropDownButton;
但它无法识别toolstripdropdownbutton。任何对此的帮助将不胜感激。谢谢。
最佳答案
代码中的问题是因为 System.Windows.Forms.ToolStripDropDownButton
是一个类,而不是命名空间。
Any idea how I can use that class to create the toolstripdropdownbutton control?
使用代码:
var item = new ToolStripDropDownButton("SomeText");
item.DropDownItems.Add(new ToolStripMenuItem("SubMenu1"));
item.DropDownItems.Add(new ToolStripMenuItem("SubMenu1"));
this.toolStrip1.Items.Add(item);
您还可以查看下面的构造函数来添加图像和事件处理程序,并在文档页面底部查看更多示例:
结果:
使用设计器:
您可以在表单上放置一个ToolStrip
,然后单击添加项目的下拉列表。然后选择DropDownButton
。
更多信息:
关于c# - 在设计工具箱中找不到 ToolStripDropDownButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33823819/