2
Answers

C# winform picturebox with a cross

TAN WhoAMI

TAN WhoAMI

11y
1.4k
1
Can anyone show me how to have a C# Winform Picturebox with a cross such that it divides into Left and Right area equally, as well as Top and Bottom area equally?

I have tried this, but does not work...

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

            Point ptCurrent = new Point(0,0);

            foreach (Point p in _points)
            {
                Point pt1 = new Point(p.X, p.Y - 10);
                Point pt2 = new Point(p.X, p.Y + 10);
                Point pt3 = new Point(p.X - 10, p.Y);
                Point pt4 = new Point(p.X + 10, p.Y);
                g.DrawLine(Pens.Black, pt1, pt2);
                g.DrawLine(Pens.Black, pt3, pt4);

            }
        }

as suggested from http://forums.codeguru.com/showthread.php?481124-how-to-mark-a-cross-on-the-picture-in-the-picture-box-using-c
Answers (2)
0
Vulpes

Vulpes

NA 163.6k 1.5m 11y
Try this:

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Point pt1 = new Point(0, pictureBox1.Size.Height / 2);
            Point pt2 = new Point(pictureBox1.Size.Width, pictureBox1.Size.Height/ 2);
            Point pt3 = new Point(pictureBox1.Size.Width / 2, 0);
            Point pt4 = new Point(pictureBox1.Size.Width / 2, pictureBox1.Size.Height);
            g.DrawLine(Pens.Black, pt1, pt2);
            g.DrawLine(Pens.Black, pt3, pt4);
        }

Accepted
0
TAN WhoAMI

TAN WhoAMI

NA 291 0 11y
thanks Vulpes for your exact and prompt answer.