通过 Region 设置 Winform 圆角,圆角大小不相同的问题

LifeChina555 2012-09-20 10:25:06



图中红色的是个Panel,我在这个Panel的Paint中

private void panel1_Paint(object sender, PaintEventArgs e)
{
GraphicsPath path = CreatePath(
new Rectangle(0, 0, panel1.Width, panel1.Height), 20);
panel1.Region = new System.Drawing.Region(path);
}


CreatePath方法如下
public static GraphicsPath CreatePath(Rectangle rect, int radius)
{
int w = rect.Width;
int h = rect.Height;

GraphicsPath path = new GraphicsPath();

int val = style.GetHashCode();
path.AddArc(1, 1, radius, radius, 180, 90);
path.AddArc(w - radius - 1, 1, radius, radius, 270, 90);
path.AddArc(w - radius - 1, h - radius - 1, radius, radius, 0, 90);
path.AddArc(1, h - radius - 1, radius, radius, 90, 90);



问题是绘出的图左上角的圆角大小和右下角圆角,明显不一样
左下角和右上角也是不一样的,不过没那么明显
请高人教导
...全文
219 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yang2948443 2012-09-21
  • 打赏
  • 举报
回复
这个不会啊,帮楼主顶一下,也学习一下。
Jia_H 2012-09-20
  • 打赏
  • 举报
回复
把AddArc里面的1换成0看看,如下。
offset改为1的时候就是你原来的结果:

int offset = 0;
path.AddArc(offset, offset, radius, radius, 180, 90);
path.AddArc(w - radius - offset, offset, radius, radius, 270, 90);
path.AddArc(w - radius - offset, h - radius - offset, radius, radius, 0, 90);
path.AddArc(offset, h - radius - offset, radius, radius, 90, 90);
return path;
LifeChina555 2012-09-20
  • 打赏
  • 举报
回复
刚刚 GraphicsPath 方法没发全
public static GraphicsPath CreatePath(Rectangle rect, int radius)
{
int w = rect.Width;
int h = rect.Height;

GraphicsPath path = new GraphicsPath();

int val = style.GetHashCode();
path.AddArc(1, 1, radius, radius, 180, 90);
path.AddArc(w - radius - 1, 1, radius, radius, 270, 90);
path.AddArc(w - radius - 1, h - radius - 1, radius, radius, 0, 90);
path.AddArc(1, h - radius - 1, radius, radius, 90, 90);
return path;
}

110,538

社区成员

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

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

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