如何为GraphicsPath应用外边界

西瓦苏拉曼尼亚人

如何为GraphicsPath应用外边界?我尝试了以下代码,但将边框应用于单个矩形而不是整个路径。

我的预期输出屏幕截图如下。

在此处输入图片说明

我尝试过的可运行示例:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        this.Load += new System.EventHandler(this.Form1_Load);
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
    }

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        GraphicsPath graphicsPath = new GraphicsPath();

        Rectangle rect1 = new Rectangle(20, 20, 100, 30);
        Rectangle rect2 = new Rectangle(20, 50, 40, 20);

        graphicsPath.StartFigure();
        graphicsPath.AddRectangle(rect1);
        graphicsPath.AddRectangle(rect2);

        graphicsPath.CloseAllFigures();
        e.Graphics.FillPath(Brushes.LightGreen, graphicsPath);
        e.Graphics.DrawPath(Pens.DarkGreen, graphicsPath);

    }
}

请建议我如何实现预期的输出。提前致谢。

理查德

使用多边形而不是矩形来绘制形状可获得所需的结果:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        this.Load += new System.EventHandler(this.Form1_Load);
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
    }

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        GraphicsPath graphicsPath = new GraphicsPath();
        Point[] pts = new Point[] { new Point(20, 20), 
                                    new Point(120, 20), 
                                    new Point(120, 50), 
                                    new Point(60, 50),        
                                    new Point(60, 70), 
                                    new Point(20, 70) };

        graphicsPath.AddPolygon(pts);

        e.Graphics.FillPath(Brushes.LightGreen, graphicsPath);
        e.Graphics.DrawPath(Pens.DarkGreen, graphicsPath);
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何为GraphicsPath应用外边界

来自分类Dev

如何做phpexcel外边界

来自分类Dev

桌子外边界线填充

来自分类Dev

HTML表格外边界多个TR

来自分类Dev

HTML表格外边界多个TR

来自分类Dev

命令执行中的额外边界数据

来自分类Dev

从文件读取时数组的外边界

来自分类Dev

R levelplot删除外边界(调整图边界)

来自分类Dev

R levelplot删除外边界(调整图边界)

来自分类Dev

gnuplot表面图中的额外边界投影线

来自分类Dev

删除切换按钮WPF的外边界

来自分类Dev

使用CSS创建多个向外边界半径

来自分类Dev

向古腾堡圆柱块的外边界添加半径

来自分类Dev

从FullCalendar v5删除日历的外边界

来自分类Dev

如何为简单的游戏设置动态边界/组件-JAVA

来自分类Dev

Pygame:如何为旋转的正方形设置边界?

来自分类Dev

如何为 Pandas DataFrame 中的异常值选择边界?

来自分类Dev

如何为创建具有特征寿命边界的对象的生产者查找通用边界

来自分类Dev

如何使元素与父元素的外边缘对齐

来自分类Dev

如何在MVC应用中设置Kendo地图边界?

来自分类Dev

如何在行之间应用边界半径和间距?

来自分类Dev

如何仅在边界底部的输入上应用线性梯度?

来自分类Dev

如何为特定应用运行rake?

来自分类Dev

如何为ziplist创建应用实例?

来自分类Dev

如何为jQuery实例应用类型保护?

来自分类Dev

如何为@ Html.DisplayFor应用CSS?

来自分类Dev

如何为应用实例创建适当的“纯”?

来自分类Dev

如何为Material UI Icon应用白色?

来自分类Dev

如何为内置验证器应用条件