Vous pouvez faire une version simple vous-même, en utilisant l'image du bouton. J'ai ma propre classe qui est dérivée de Button
.
Je mis en place l'image (qui est d'une flèche vers le bas) comme ceci:
{
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);
}
Si vous vouliez aussi une icône, comme dans l'OP, vous pouvez utiliser un BackgroundImage
et un rembourrage approprié, comme si :
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);
est ici un bouton de mes en action:
Ha, je ne savais pas que l'image était un de l .NET la bibliothèque Je viens de faire une recherche d'image google sur le bouton divisé et j'ai juste choisi le meilleur que j'ai trouvé. – Jamiegs