Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#非矩形图片框_C#_Transparency_Picturebox - Fatal编程技术网

C#非矩形图片框

C#非矩形图片框,c#,transparency,picturebox,C#,Transparency,Picturebox,有没有办法创建非矩形的图片框。我的圆形应该重叠,如果可能的话应该在不同的图片框中。。 我试过了,但是你不能同时看到两个重叠的图片框,只能看到一个 下面是我的测试结果: 您可以将椭圆添加到GraphicsPath,然后从中构建新区域,从而使PictureBoxes成为圆形 下面是一个简单的例子: public class Target : PictureBox { public Target() { this.Size = new Size(100, 100);

有没有办法创建非矩形的图片框。我的圆形应该重叠,如果可能的话应该在不同的图片框中。。 我试过了,但是你不能同时看到两个重叠的图片框,只能看到一个

下面是我的测试结果:

您可以将椭圆添加到GraphicsPath,然后从中构建新区域,从而使PictureBoxes成为圆形

下面是一个简单的例子:

public class Target : PictureBox
{
    public Target()
    {
        this.Size = new Size(100, 100);
        this.Paint += Target_Paint;
        Rectangle rc = this.ClientRectangle;
        rc.Inflate(-10, -10);
        System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
        gp.AddEllipse(rc);
        this.Region = new Region(gp);
    }

    void Target_Paint(object sender, PaintEventArgs e)
    {
        Rectangle rc = this.ClientRectangle;
        rc.Inflate(-10, -10);
        using (Pen pen = new Pen(Color.Blue, 5))
        {
            e.Graphics.DrawEllipse(pen, rc);
        }
        rc = new Rectangle(new Point(this.Size.Width / 2, this.Size.Height / 2), new Size(1, 1));
        rc.Inflate(9, 9);
        e.Graphics.FillEllipse(Brushes.Red, rc);
    }
}
编译后,新控件将显示在工具箱的顶部

下面是一个屏幕截图,其中三个相互重叠:

不要使用任何控件。尝试直接在容器中绘图--确保它是双缓冲的。我想您可以使用GraphicPath通过创建自定义透明遮罩来“裁剪”图片框。使用WPF是可行的。