我正在寻找.NET WinForms中的拆分按钮。其中一边是一个按钮,另一边有一个下拉按钮。
我看到它们在窗口中到处使用,比如在Visual Studio的另存为窗口中,所以我认为它们一定是在某个库中拥有控件。
我知道有一个用于工具条,但我需要一个可以在工具条之外使用的工具条。
有没有微软的库有一个,或者最好是免费的库?我使用的是.NET 3.5
举个例子:
发布于 2015-01-15 19:37:28
你可以自己做一个简单的版本,使用按钮的图像。我有自己的类,它是从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);
}
如果您还想要一个图标,就像在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);
这是我的一个实际操作按钮:
https://stackoverflow.com/questions/1597320
复制相似问题