viv*_*ain -1 .net c# user-controls picturebox winforms
这是否可以PictureBox在 Windows 窗体中使用三角形控件而不是矩形控件?
您有一些选择,例如:
示例 1
在此示例中,控制区域仅限于三角形。
public class TriangularPictureBox:PictureBox
{
protected override void OnPaint(PaintEventArgs pe)
{
using (var p = new GraphicsPath())
{
p.AddPolygon(new Point[] {
new Point(this.Width / 2, 0),
new Point(0, Height),
new Point(Width, Height) });
this.Region = new Region(p);
base.OnPaint(pe);
}
}
}
Run Code Online (Sandbox Code Playgroud)
示例 2
在此示例中,将仅在控件的三角形区域上进行绘制。
public class TriangularPictureBox:PictureBox
{
protected override void OnPaint(PaintEventArgs pe)
{
using (var p = new GraphicsPath())
{
p.AddPolygon(new Point[] {
new Point(this.Width / 2, 0),
new Point(0, Height),
new Point(Width, Height) });
pe.Graphics.SetClip(p);
base.OnPaint(pe);
}
}
}
Run Code Online (Sandbox Code Playgroud)