WinForm中,PictureBox控件,怎样显示圆角,求代码

feyyee 2010-10-06 10:52:24
WinForm中,PictureBox控件,怎样显示圆角,求代码。
如果设置PictureBox的边框样式,则它显示的是直角,怎样显示圆角呢?
...全文
2474 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Snowdust 2010-10-06
  • 打赏
  • 举报
回复
public void DrawRoundRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius)
{
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

gp.AddLine(X + radius, Y, X + width - (radius * 2), Y);

gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90);

gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2));

gp.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90);

gp.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height);

gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90);

gp.AddLine(X, Y + height - (radius * 2), X, Y + radius);

gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90);

gp.CloseFigure();

g.DrawPath(p, gp);
gp.Dispose();
}

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
DrawRoundRect(e.Graphics, Pens.Black, 0, 0, pictureBox1.Width - 1, pictureBox1.Height - 1, 10);
}

110,536

社区成员

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

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

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