سؤال

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.

هل كانت مفيدة؟

المحلول

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

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.

نصائح أخرى

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

    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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top