.NET Winforms中的拆分按钮

Jam*_*egs 17 .net controls winforms

我正在寻找.NET WinForms中的分割按钮.一侧是按钮而另一侧有下拉按钮的类型.

我看到它们在Windows中全部使用,就像在Visual Studio中另存为窗口一样,所以我想他们必须在某些库中拥有控件.

我知道有一个工具条,但我需要一个可以在工具条之外使用的工具条.

是否有一个Microsoft库有一个或最好是一个免费的库?我正在使用.NET 3.5

举个例子: Example Button

noe*_*cus 7

你可以使用按钮的图像自己做一个简单的版本.我有自己的类派生自Button.

我设置了图像(向下箭头),如下所示:

{
    this.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
    this.Image = YourResources.split_button; // Your down-arrow image

    this.TextImageRelation = System.Windows.Forms.TextImageRelation.TextBeforeImage;
}


protected override void OnClick(EventArgs e)
{
    var clickPos = this.PointToClient(new System.Drawing.Point(MousePosition.X, MousePosition.Y));

    // If click is over the right-hand portion of the button show the menu
    if (clickPos.X >= (Size.Width - Image.Width))
        ShowMenuUnderControl()
    else
        base.OnClick(e);
}

// If you want right-mouse click to invoke the menu override the mouse up event
protected override void OnMouseUp(MouseEventArgs mevent)
{
    if ((mevent.Button & MouseButtons.Right) != 0)
        ShowMenuUnderControl();
    else
        base.OnMouseUp(mevent);
}

// Raise the context menu
public void ShowMenuUnderControl()
{
    splitMenuStrip.Show(this, new Point(0, this.Height), ToolStripDropDownDirection.BelowRight);
}
Run Code Online (Sandbox Code Playgroud)

如果您还想要一个图标,就像在OP中一样,您可以使用BackgroundImage适当的填充,如下所示:

this.BackgroundImageLayout = ImageLayout.None;
this.BackgroundImage = YourResources.ButtonIcon;

// Add padding so the text doesn't overlay the background image
this.Padding = new Padding(
    this.Padding.Left + this.BackgroundImage.Width,
    this.Padding.Top,
    this.Padding.Right,
    this.Padding.Bottom);
Run Code Online (Sandbox Code Playgroud)

这是我的一个按钮:
c#winforms拆分按钮,菜单和箭头和图标