是否可以有三角形的PictureBox而不是矩形的PictureBox? [英] Is this possible to have triangular PictureBox instead of the rectangular one?

查看:82
本文介绍了是否可以有三角形的PictureBox而不是矩形的PictureBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is this possible to have triangular PictureBox control in windows forms instead of the rectangular one?

推荐答案

您有一些选择,例如:

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

示例1

在此示例中,控制区域限制为三角形.

In this example, the region of control limited to a triangular shape.

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

在此示例中,绘画将仅在控件的三角形区域上完成.

In this example, the painting will be done only on a triangular area of the control.

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

这篇关于是否可以有三角形的PictureBox而不是矩形的PictureBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆