只绘制一个矩形的角

时间:2020-12-15 19:04:28

I used

我用了

Pen pen = new Pen(Color.Red);
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;

to shape the border of rectangle but now I only need to show the corner of that rectangle.

塑造矩形的边框,但现在我只需要显示该矩形的角落。

2 个解决方案

#1


3  

You can draw it by yourself by DrawLine function in Paint event handler, something like this:

您可以通过Paint事件处理程序中的DrawLine函数自己绘制它,如下所示:

Pen pen = new Pen(Color.Red);

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

    pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
}

private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
    Graphics g = e.Graphics;

    g.DrawLine(pen, 0, 0, pictureBox1.Right, 0);

    g.DrawLine(pen, 0, 0, 0, pictureBox1.Bottom);
}

It's a use case, maybe you need other coordinates, but you can fix it easily.

这是一个用例,也许您需要其他坐标,但您可以轻松修复它。

#2


2  

You could use 2 lines to get the effect you want:

您可以使用2行来获得所需的效果:

    private void MainForm_Paint(object sender, PaintEventArgs e)
    {
        Pen pen = new Pen(Color.Red);
        pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
        e.Graphics.DrawLine(pen, 0, 0, 50, 0 );
        e.Graphics.DrawLine(pen, 0, 0, 0, 50);
    }

This draws the corner of a rectangle in the top left corner of the form.

这将在窗体的左上角绘制一个矩形的角。

#1


3  

You can draw it by yourself by DrawLine function in Paint event handler, something like this:

您可以通过Paint事件处理程序中的DrawLine函数自己绘制它,如下所示:

Pen pen = new Pen(Color.Red);

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

    pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
}

private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
    Graphics g = e.Graphics;

    g.DrawLine(pen, 0, 0, pictureBox1.Right, 0);

    g.DrawLine(pen, 0, 0, 0, pictureBox1.Bottom);
}

It's a use case, maybe you need other coordinates, but you can fix it easily.

这是一个用例,也许您需要其他坐标,但您可以轻松修复它。

#2


2  

You could use 2 lines to get the effect you want:

您可以使用2行来获得所需的效果:

    private void MainForm_Paint(object sender, PaintEventArgs e)
    {
        Pen pen = new Pen(Color.Red);
        pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
        e.Graphics.DrawLine(pen, 0, 0, 50, 0 );
        e.Graphics.DrawLine(pen, 0, 0, 0, 50);
    }

This draws the corner of a rectangle in the top left corner of the form.

这将在窗体的左上角绘制一个矩形的角。

相关文章