C# picturebox重写成圆形
pictureBox的系统形式是方形,可不可以变成圆形的呢?重写控件可以实现吗?可以的话求路过的大神赐教?不可以的话请问我怎样才可以是图片在pictureBox上圆形显示...
pictureBox的系统形式是方形,可不可以变成圆形的呢?重写控件可以实现吗?可以的话求路过的大神赐教?不可以的话请问我怎样才可以是图片在pictureBox上圆形显示呢?
谢谢大家了!!! 展开
谢谢大家了!!! 展开
1个回答
2015-07-16 · 知道合伙人软件行家
关注
展开全部
只要设置Picturebox的Region属性就可以了,如下
using System.Drawing.Drawing2D;
private void button1_Click(object sender, EventArgs e)
{
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(pictureBox1.ClientRectangle);
Region region = new Region(gp);
pictureBox1.Region = region;
gp.Dispose();
region.Dispose();
}
using System.Drawing.Drawing2D;
private void button1_Click(object sender, EventArgs e)
{
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(pictureBox1.ClientRectangle);
Region region = new Region(gp);
pictureBox1.Region = region;
gp.Dispose();
region.Dispose();
}
更多追问追答
追问
这个是吧picturebox上画了一个圆,并没有pictureBox重写成圆形!!!!
追答
public class MyPic:PictureBox
{
protected override void OnCreateControl()
{
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(this.ClientRectangle);
Region region = new Region(gp);
this.Region = region;
gp.Dispose();
region.Dispose();
base.OnCreateControl();
}
}
private void Form2_Load(object sender, EventArgs e)
{
MyPic pic = new MyPic();
pic.Name = "p1";
pic.Image = WindowsFormsApplication1.Properties.Resources.cnt_bg_01;
pic.Width = 500;
pic.Height = 300;
this.Controls.Add(pic);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询