c# - 在设计工具箱中找不到 ToolStripDropDownButton

标签 c# winforms toolstripdropdown

我正在制作一个表单,并希望使用 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); 

您还可以查看下面的构造函数来添加图像和事件处理程序,并在文档页面底部查看更多示例:

结果:

enter image description here

使用设计器:

您可以在表单上放置一个ToolStrip,然后单击添加项目的下拉列表。然后选择DropDownButton

enter image description here

更多信息:

关于c# - 在设计工具箱中找不到 ToolStripDropDownButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33823819/

相关文章:

c# - 如何解决泛型错误 CS0311?

javascript - 加载集线器时出错。 HTML5/js 前端和 C# 后端

c# - 如何查询所有实现接口(interface)的表

c# - 如何在不清空 SelectedNode 中的当前节点的情况下使 TreeView.SelectedNode 属性清空?

.net - WPF 中的 ToolStripDropDownButton 等价物?

c# - 如何从单击的 ToolStripDropDownButton 项中获取字符串?

javascript - 在 MVC razor View 中使用浏览器的后退按钮后清除表单元素

.net - winforms有没有好的免费的devexpress数据网格替代品?

c# - Infragistics UltraGrid - 网格初始化后的事件

c# - 当 DropDownStyle 为 Simple 时,ToolStripCombobox 显示在屏幕左上角