16
我正在尋找在.NET的WinForms一個拆分按鈕。一邊是按鈕而另一邊有下拉按鈕的那種。拆分按鈕
我看到他們用遍了櫥窗,就像在Visual Studio另存爲窗口,所以我想他們已經得到了在一些圖書館的控制。
我知道有一個toolstrips,但我需要一個那toolstrips之外使用。
是否存在有一個或最好是免費的圖書館微軟庫? 我使用.NET 3.5
舉一個例子:
我正在尋找在.NET的WinForms一個拆分按鈕。一邊是按鈕而另一邊有下拉按鈕的那種。拆分按鈕
我看到他們用遍了櫥窗,就像在Visual Studio另存爲窗口,所以我想他們已經得到了在一些圖書館的控制。
我知道有一個toolstrips,但我需要一個那toolstrips之外使用。
是否存在有一個或最好是免費的圖書館微軟庫? 我使用.NET 3.5
舉一個例子:
你可以自己做一個簡單的版本,使用該按鈕的圖像。我有我自己的課程,它來自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);
這裏是我的行動按鈕:
哈,我不知道該圖像是從.NET升ibrary。 我剛剛做了一個谷歌圖片搜索拆分按鈕,只是選擇了我發現的最好看的一個。 – Jamiegs 2009-10-22 19:18:50