Bạn có thể làm một phiên bản đơn giản chính mình, sử dụng hình ảnh của nút. Tôi có lớp học của riêng tôi có nguồn gốc từ Button
.
tôi thiết lập hình ảnh (đó là một mũi tên xuống) như sau:
{
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);
}
Nếu bạn cũng muốn một biểu tượng, như trong OP, bạn có thể sử dụng một BackgroundImage
và phù hợp đệm, như vậy :
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);
Dưới đây là một nút của tôi trong hành động:
Hà, tôi đã không nhận ra rằng hình ảnh là một từ NET l ibrary. Tôi đã thực hiện tìm kiếm hình ảnh trên nút chia nhỏ của google và chỉ chọn một hình ảnh đẹp nhất mà tôi tìm thấy. – Jamiegs