这可能是三角形PictureBox而不是矩形的吗?
这是否可以在Windows窗体中使用三角形PictureBox
控件而不是矩形窗体?
你有一些选择,例如:
- 您可以将控制区域设置为三角形。
- 您只能在控件的三角形区域进行绘制。
例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); } } }
例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); } } }