这可能有三角形的图片框而不是矩形的吗? [英] Is this possible to have triangular PictureBox instead of the rectangular one?

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

问题描述

这是否可以在 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);
        }
    }
}

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

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