1

ToolStripDropDownButtonを3 つToolStripButtonの sで作成しています。そして、2番目のボタンの後にセパレーターを追加したいと思います。

これが私が持っているコードです。

using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        internal ToolStripDropDownButton dropDownButton1;
        internal ToolStripDropDown dropDown;
        internal ToolStripButton buttonRed;
        internal ToolStripButton buttonBlue;
        internal ToolStripButton buttonYellow;

        public Form1()
        {
            InitializeComponent();

            dropDownButton1 = new ToolStripDropDownButton();
            dropDown = new ToolStripDropDown();
            dropDownButton1.Text = "A";

            dropDownButton1.DropDown = dropDown;
            dropDownButton1.DropDownDirection = ToolStripDropDownDirection.Right;
            dropDownButton1.ShowDropDownArrow = false;

            buttonRed = new ToolStripButton();
            buttonRed.ForeColor = Color.Red;
            buttonRed.Text = "A";

            buttonBlue = new ToolStripButton();
            buttonBlue.ForeColor = Color.Blue;
            buttonBlue.Text = "A";

            buttonYellow = new ToolStripButton();
            buttonYellow.ForeColor = Color.Yellow;
            buttonYellow.Text = "A";

            ToolStripSeparator s = new ToolStripSeparator();

            dropDown.Items.AddRange(new ToolStripItem[] { buttonRed, buttonBlue, s, buttonYellow });
            toolStrip1.Items.Add(dropDownButton1);
        }
    }
}

問題は、セパレーターが垂直に表示されていることです。

ここに画像の説明を入力

横向きに表示するにはどうすればよいですか?

4

1 に答える 1

4

ToolStripDropDownLayoutStyleプロパティを設定する必要があります。デフォルトでは ですToolStripLayoutStyle.Flowが、に設定する必要がありToolStripLayoutStyle.VerticalStackWithOverflowます。

ToolStripDropDownまたは、インスタンスの作成と構成をスキップして、そのプロパティを使用しToolStripItemて を直接追加することもできます。ToolStripDropDownButtonDropDownItems

dropDownButton1.DropDownItems.AddRange(
    new ToolStripItem[] { buttonRed, buttonBlue, s, buttonYellow });
于 2012-11-19T13:29:27.523 に答える