3

我用了

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

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

4

2 回答 2

3

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

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

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

于 2013-12-17T06:12:28.480 回答
2

您可以使用 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);
    }

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

于 2013-12-17T06:19:31.780 回答