在.NET下,如何画圆角矩形? -=100分=-

Colin-Han 2006-04-13 08:12:57
如题。
...全文
298 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
copico 2006-04-13
  • 打赏
  • 举报
回复
画弧+四条边
代码蜗牛sky 2006-04-13
  • 打赏
  • 举报
回复
protected override void OnPaintBackground(PaintEventArgs pevent)
{
//填充大的圆角矩形框
Graphics g = pevent.Graphics;
g.FillRectangle( Brushes.Lime, 0, 0, this.ClientSize.Width, this.ClientSize.Height );

System.Drawing.Drawing2D.GraphicsPath framePath = Utils.CreateRoundedRectPath(this.ClientRectangle, 5 );

using ( System.Drawing.Drawing2D.LinearGradientBrush frameLgb =
new System.Drawing.Drawing2D.LinearGradientBrush( this.ClientRectangle,
Color.SteelBlue, Color.LightBlue, System.Drawing.Drawing2D.LinearGradientMode.Vertical ) )
{
g.FillPath( frameLgb, framePath );
}

//填充小的圆角矩形框:文本区
Rectangle textAreaRectangle = new Rectangle(this.ClientRectangle.Location.X + 5,
this.ClientRectangle.Location.Y + 5,this.ClientRectangle.Size.Width - 10,
this.ClientRectangle.Size.Height - 10);

System.Drawing.Drawing2D.GraphicsPath textAreaPath = Utils.CreateRoundedRectPath(textAreaRectangle,5);
g.FillPath( Brushes.White, textAreaPath );
}
代码蜗牛sky 2006-04-13
  • 打赏
  • 举报
回复
public static GraphicsPath CreateRoundedRectPath( Rectangle rect, int radius )
{
GraphicsPath rectPath = new GraphicsPath();

// Add the line on the top:
rectPath.AddLine( rect.Left + radius, rect.Top,
rect.Right - radius, rect.Top );
// Add the arc at the top right corner:
rectPath.AddArc( rect.Right - 2 * radius, rect.Top,
radius * 2, radius * 2 ,
270, 90 );
// Line down the right:
rectPath.AddLine( rect.Right, rect.Top + radius,
rect.Right, rect.Bottom - 10 );
// Bottom Right quarter circle:
rectPath.AddArc( rect.Right - radius * 2, rect.Bottom - radius * 2,
radius * 2, radius * 2,
0, 90 );
// bottom line:
rectPath.AddLine( rect.Right - 2 * radius, rect.Bottom ,
rect.Left + radius, rect.Bottom );
// Bottom left quarter circle:
rectPath.AddArc( rect.Left, rect.Bottom - 2 * radius,
2 * radius, 2 * radius, 90, 90 );
// Up the left side:
rectPath.AddLine( rect.Left, rect.Bottom - radius,
rect.Left, rect.Top + radius );
// Upper left arc:
rectPath.AddArc( rect.Left, rect.Top,
2 * radius, 2 * radius, 180, 90 );

return rectPath;
}

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧