最简单的思路....
private
void
Form_Load (
object
sender, EventArgs e)
{
this .textBox1.Region = new Region (GetRoundRectPath( new RectangleF( 0 , 0 , this .textBox1.Width, this .textBox1.Height),10f));
}
// 适合调整参数radius...
public GraphicsPath GetRoundRectPath (RectangleF rect, float radius)
{
return GetRoundRectPath (rect.X, rect.Y, rect.Width, rect.Height, radius);
}
public GraphicsPath GetRoundRectPath ( float X, float Y, float width, float height, float radius)
{
GraphicsPath path = new GraphicsPath ();
path.AddLine (X + radius, Y, (X + width) - (radius * 2f), Y);
path.AddArc ((X + width) - (radius * 2f), Y, radius * 2f, radius * 2f, 270f, 90f);
path.AddLine (( float )(X + width), ( float )(Y + radius), ( float )(X + width), ( float )((Y + height) - (radius * 2f)));
path.AddArc (( float )((X + width) - (radius * 2f)), ( float )((Y + height) - (radius * 2f)), ( float )(radius * 2f), ( float )(radius * 2f), 0f, 90f);
path.AddLine (( float )((X + width) - (radius * 2f)), ( float )(Y + height), ( float )(X + radius), ( float )(Y + height));
path.AddArc (X, (Y + height) - (radius * 2f), radius * 2f, radius * 2f, 90f, 90f);
path.AddLine (X, (Y + height) - (radius * 2f), X, Y + radius);
path.AddArc (X, Y, radius * 2f, radius * 2f, 180f, 90f);
path.CloseFigure ();
return path;
}
{
this .textBox1.Region = new Region (GetRoundRectPath( new RectangleF( 0 , 0 , this .textBox1.Width, this .textBox1.Height),10f));
}
// 适合调整参数radius...
public GraphicsPath GetRoundRectPath (RectangleF rect, float radius)
{
return GetRoundRectPath (rect.X, rect.Y, rect.Width, rect.Height, radius);
}
public GraphicsPath GetRoundRectPath ( float X, float Y, float width, float height, float radius)
{
GraphicsPath path = new GraphicsPath ();
path.AddLine (X + radius, Y, (X + width) - (radius * 2f), Y);
path.AddArc ((X + width) - (radius * 2f), Y, radius * 2f, radius * 2f, 270f, 90f);
path.AddLine (( float )(X + width), ( float )(Y + radius), ( float )(X + width), ( float )((Y + height) - (radius * 2f)));
path.AddArc (( float )((X + width) - (radius * 2f)), ( float )((Y + height) - (radius * 2f)), ( float )(radius * 2f), ( float )(radius * 2f), 0f, 90f);
path.AddLine (( float )((X + width) - (radius * 2f)), ( float )(Y + height), ( float )(X + radius), ( float )(Y + height));
path.AddArc (X, (Y + height) - (radius * 2f), radius * 2f, radius * 2f, 90f, 90f);
path.AddLine (X, (Y + height) - (radius * 2f), X, Y + radius);
path.AddArc (X, Y, radius * 2f, radius * 2f, 180f, 90f);
path.CloseFigure ();
return path;
}