Click here to Skip to main content
14,392,925 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi! Every body!
I'm writing an application: Load photos from PC then displayed on the picturebox, namely:
  When the user presses F1, a line will be drawn up at the picture that the mouse coordinates are pointing to. My problem is when the user presses F1 again, the line will be drawn initially deleted instead new line will be drawn at the new location.
I also refer to some links but no solutions. We wish all the suggestions and help so that I can complete my project.
A link has reference number:
Thank you all very much
BillWoodruff 9-Oct-14 7:26am
A line drawn "up at the picture" from where ?

Assuming you are drawing the lines in the Paint Event, and you want the lines to persist, you are going to need to maintain a list of lines to draw and re-draw them.

Post carefully selected examples from your actual code showing where you are stuck.
ZurdoDev 9-Oct-14 8:06am
You'll need to fix the code then.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi BillWoodruff! Thanks for your answer.
Line is drawn from the following functions, this function is called in the keydown event of the form.
public void DrawLine(PictureBox pb, Point p, Color color)
                Point p1 = new Point();
                Point p2 = new Point();
                Point p3 = new Point();
                Point p4 = new Point();
                //Draw as plus sign
                p1.X = p.X;
                p1.Y = p.Y - 10;
                p2.X = p.X;
                p2.Y = p.Y + 10;
                p3.X = p.X - 10;
                p3.Y = p.Y;
                p4.X = p.X + 10;
                p4.Y = p.Y;
                Bitmap bmp = (Bitmap)pb.Image;
                Graphics g = Graphics.FromImage(bmp);
                Pen pe = new Pen(color, 3);
                g.DrawLine(pe, p1, p2);
                g.DrawLine(pe, p3, p4);
                pb.Image = bmp;
                MessageBox.Show("Please select image let draw!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

And when the user draw a new line, the line has been drawn previously been removed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100