圆角PICTUREBOX

gui41021 2014-11-24 05:08:15
新手求指点

WINFORM下 想画一个圆角PICTUREBOX

用的代码:

//圆角pic
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);
}
效果图:

矩形画出来了 图片还是方的

引用
this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);

请问如何修改?多谢
...全文
335 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
卧_槽 2014-11-26
  • 打赏
  • 举报
回复
设置Region
gui41021 2014-11-26
  • 打赏
  • 举报
回复
谢谢各位~~~~~~~~~~~~·
害羞的大叔 2014-11-25
  • 打赏
  • 举报
回复
背景颜色设为透明,填充颜色时只填充圆角内部。
good_jobs 2014-11-25
  • 打赏
  • 举报
回复
picbox.region=new region(graphicpath);
tanta 2014-11-25
  • 打赏
  • 举报
回复
1、用wpf很简单,建议学 2、如必须用winform,只是要视觉呈现的话,修改图片,做成圆角矩形的样子,然后设置picture图片即可。
gui41021 2014-11-25
  • 打赏
  • 举报
回复
顶 请指点 。
Mittermeyer 2014-11-25
  • 打赏
  • 举报
回复
需要设置PictureBox 的Region属性。
exception92 2014-11-24
  • 打赏
  • 举报
回复
新手都别学Winform下话picture的圆角了,学WPF下的画圆角吧。
l2999019 2014-11-24
  • 打赏
  • 举报
回复
你要重写一个新的PICBOX..

110,536

社区成员

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

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

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