c# - 如何将两个 ToolStripComboBox 和 Separator 水平添加到一个 ToolStripDropMenuItem 中?

标签 c# winforms toolstrip toolstripdropdown toolstripitem

我认为这应该很简单。但我还没见过。我想做这样的事情:

DropDown -> DropDownItem1 [ComboBox1 [|] ComboBox2]、DropDownItem2 [...]、DropDownItem3 [...];

我在 ToolStrip 中使用 ToolStripDropDownButton。我正在使用 C# 进行编程。感谢您的建议。

类似:https://s18.postimg.org/nd9r35jpl/c89a195a3b6e8dac6e7753af6b0b8a6c.png

致以诚挚的问候

最佳答案

看来您正在寻找这样的布局:

enter image description here

为此,您不需要创建任何自定义控件。只需使用ToolStrip的常用功能即可。您需要设置LayoutStyle属性到合适的值。

示例

private void Form1_Load(object sender, EventArgs e)
{
    var dropdown = new ToolStripDropDown();

    //Define style
    dropdown.LayoutStyle = ToolStripLayoutStyle.Table;
    var settings = (dropdown.LayoutSettings as TableLayoutSettings);
    settings.ColumnCount = 3;

    //First Item    
    var item1 = new ToolStripMenuItem("Some Sub Menu");
    dropdown.Items.Add(item1);
    settings.SetColumnSpan(item1, 3); //Set column span to fill the row

    //First Combo
    var combo1 = new ToolStripComboBox("combo1");
    combo1.Items.AddRange(new string[] { "Item1", "Item2", "Item3" });
    dropdown.Items.Add(combo1);

    //Separator
    dropdown.Items.Add("-");

    //Second Combo
    var combo2 = new ToolStripComboBox("combo2");
    combo2.Items.AddRange(new string[] { "Item1", "Item2", "Item3" });
    dropdown.Items.Add(combo2);

    //Last item
    var item2 = new ToolStripMenuItem("Some Othe Sub Menu");
    dropdown.Items.Add(item2);
    settings.SetColumnSpan(item2, 3); //Set column span to fill the row

    toolStripDropDownButton1.DropDown = dropdown;
}

关于c# - 如何将两个 ToolStripComboBox 和 Separator 水平添加到一个 ToolStripDropMenuItem 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40382105/

相关文章:

c# - DirectoryExists ("c:temp\\foo") 当目录不存在时返回真!

c# - Excel:插入查询引发错误消息 "Operation must use an updateable query"

c# - 多服务器部署的 ASP.net 解决方案注意事项

c# - 当 ConcurrentQueue 有太多项目时工作线程阻塞

c# - 从 F# 查看 C# Windows 窗体项目代码

c# - 输入时移除按钮边框

c# - 在同一行有多个工具条

c++ - 为什么我在工具条上得到一条垂直线?

c# - 适用于 Excel 2007 和 2010 的 Excel 插件

c# - 如何避免带有圆角的可缩放用户控件的彩色边框的视觉伪影?