• 全部
  • C#综合技术
  • C#互联网桌面应用
  • AppLauncher
  • WinForm&WPF
  • C#开发新技术
  • 问答

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

Colin-Han 2006-04-13 08:12:57
如题。
...全文
225 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
copico 2006-04-13
画弧+四条边
回复
甜味牛牛 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 );
}
回复
甜味牛牛 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;
}
回复
相关推荐
发帖
C#
创建于2007-09-28

10.5w+

社区成员

.NET技术 C#
申请成为版主
帖子事件
创建了帖子
2006-04-13 08:12
社区公告

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