图片框C#中的圆角边

如何在图片框控件中舍入边缘。 我想获得像椭圆这样的角度,但我不知道该怎么做。 我用C#。 谢谢!

是的,没问题,您可以使用Region属性为控件赋予任意形状。 在项目中添加一个新类并粘贴下面显示的代码。 编译。 将新控件从工具箱顶部拖放到表单上。

using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; class OvalPictureBox : PictureBox { public OvalPictureBox() { this.BackColor = Color.DarkGray; } protected override void OnResize(EventArgs e) { base.OnResize(e); using (var gp = new GraphicsPath()) { gp.AddEllipse(new Rectangle(0, 0, this.Width-1, this.Height-1)); this.Region = new Region(gp); } } } 

在表单上放置1个图片框并编写此代码也可以更改宽度和高度旁边的减号以获得最佳结果

  System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.AddEllipse(0, 0, pictureBox1.Width - 3, pictureBox1.Height - 3); Region rg = new Region(gp); pictureBox1.Region = rg; 

在此处输入图像描述

圆角处的

如果是这样,请查看http://social.msdn.microsoft.com/forums/en-US/winforms/thread/603084bb-1aae-45d1-84ae-8544386d58fd

 Rectangle r = new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height); System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); int d = 50; gp.AddArc(rX, rY, d, d, 180, 90); gp.AddArc(rX + r.Width - d, rY, d, d, 270, 90); gp.AddArc(rX + r.Width - d, rY + r.Height - d, d, d, 0, 90); gp.AddArc(rX, rY + r.Height - d, d, d, 90, 90); pictureBox1.Region = new Region(gp); 

谢谢你,汉斯。 但我也需要光滑的外观。 我对这个问题进行了一些研究,但我找不到解决方案。 然后我尝试自己做,并找到了下面的解决方案。 也许其他人需要它。

 protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); using (GraphicsPath gp = new GraphicsPath()) { gp.AddEllipse(0, 0, this.Width - 1, this.Height - 1); Region = new Region(gp); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.DrawEllipse(new Pen(new SolidBrush(this.BackColor), 1), 0, 0, this.Width - 1, this.Height - 1); } }