GraphicsPath
class provides several
Methods (System.Drawing.Drawing2D)[
^]. One of them is
GraphicsPath.AddRectangle Method (Rectangle) (System.Drawing.Drawing2D)[
^]. At the bottom of destination page, you'll find an example.
If you would like to create button with custom shape, you have to create custom class wich inherits from control. See:
Mick Doherty's .net Button Tips[
^]
How to: Create a Shaped Windows Form | Microsoft Docs[
^]
Walkthrough: Creating a Windows Forms Control That Takes Advantage of Visual Studio Design-Time Features | Microsoft Docs[
^]
Introduction to the Line and Shape Controls (Visual Studio) | Microsoft Docs[
^]
Code Magazine: Shaped .NET Windows Forms[
^]
Another way is to override
OnPaint
method for your control.
public class TriangleButton :Button
{
protected override void OnPaint(PaintEventArgs pevent)
{
Rectangle rect = this.ClientRectangle;
using (GraphicsPath path = new GraphicsPath())
{
path.AddPolygon(new Point []{new Point(rect.X+rect.Width/2,rect.Y),new Point(rect.X,rect.Y+rect.Height),new Point(rect.X+rect.Width,rect.Y+rect.Height)});
path.CloseFigure();
this.Region = new Region(path);
pevent.Graphics.FillPath(SystemBrushes.ButtonShadow, path);
}
}
}
usage:
TriangleButton shb = new TriangleButton();
shb.Name = "ShapedButton1";
shb.Location = new Point(50, 50);
shb.Parent = this;
Good luck!