在图片框C#圆边 [英] Rounded edges in picturebox C#
本文介绍了在图片框C#圆边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何轮PictureBox控件的边缘。我想要得到的角度想椭圆形有,但我不知道如何做到这一点。我使用C#。谢谢!
How to round edges in picturebox control. I Want to get angles like ellipse have but i dont know how to do it. I Use C#. Thanks!
推荐答案
好的,没问题,你可以给一个控制其Region属性的任意形状。添加一个新类到您的项目并粘贴如下所示的code。编译。从工具箱的上方新的控制到您的表单。
Yes, no problem, you can give a control an arbitrary shape with its Region property. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form.
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);
}
}
}
这篇关于在图片框C#圆边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文