使用Region属性。
先创建GraphicsPath对像,在其中实现一个形状,然后应用于控件的region属性.
例如创建圆形按钮:
private void roundButton_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Drawing2D.GraphicsPath buttonPath = new System.Drawing.Drawing2D.GraphicsPath();
System.Drawing.Rectangle newRectangle = roundButton.ClientRectangle;
newRectangle.Inflate(-10, -10);
e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle);
newRectangle.Inflate( 1, 1);
buttonPath.AddEllipse(newRectangle);.
roundButton.Region = new System.Drawing.Region(buttonPath);
}