【问题标题】:Is this possible to have triangular PictureBox instead of the rectangular one?这可能有三角形的图片框而不是矩形的吗?
【发布时间】:2016-02-17 20:36:04
【问题描述】:

这是否可以在 Windows 窗体中使用三角形 PictureBox 控件而不是矩形控件?

【问题讨论】:

    标签: c# .net winforms user-controls picturebox


    【解决方案1】:

    你有一些选择,例如:

    • 您可以将控制区域设置为三角形。
    • 您只能在控件的三角形区域内绘制。

    示例 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);
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-06
      相关资源
      最近更新 更多