Click here to Skip to main content
15,850,360 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear friends ,
i have this code for drawline over to picturebox and now i want when user click the picturebox then particuler point show as a starpoint(like *,@,.) show as a point.

2. And i want whenever it cross the line then it will give the alert , i am trying bt not work properly.

C#
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
                 

            pointArray[iNumberofClicks].X = e.X;
            pointArray[iNumberofClicks].Y = e.Y;
            Pen PenSpikes = new Pen(Color.Green);
            SolidBrush solidBrush = new SolidBrush(Color.Blue);

            if(iNumberofClicks==0)
            {
                 a = e.X;
                 b = e.Y;
            }

            iNumberofClicks++;
            if (iNumberofClicks > 1)
            {
                Point[] CurrentpointArray = new Point[iNumberofClicks];

                for (int aa = 0; aa < iNumberofClicks; aa++)
                {
                    CurrentpointArray[aa].X = pointArray[aa].X;
                    CurrentpointArray[aa].Y = pointArray[aa].Y;

                }

               
               Graphics offScreenDC = Graphics.FromImage(pictureBox1.Image);
                offScreenDC.DrawLines(PenSpikes, CurrentpointArray);
                offScreenDC.Dispose();
                pictureBox1.Refresh();
                
               
}
}
for (int j = 1; j < CurrentpointArray.Length;j++ )
              {
                  if ((Convert.ToInt16(CurrentpointArray[j].X) == a && Convert.ToInt16(CurrentpointArray[j].Y) == b) )
                  {
                      MessageBox.Show("alert");
                      break;
                  }
              }
Posted
Updated 18-May-12 21:50pm
v3

1 solution

You should start solving this problem from not using PictureBox. It is useful only in some simplest cases and becomes a hassle when you try to do something more advanced.

I explain it in my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^].

Some more detailed explanations on what to do instead in my past answers:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^].

—SA
 
Share this answer
 
Comments
Shahin Khorshidnia 20-May-12 2:36am    
Good explanations. (+5)
Sergey Alexandrovich Kryukov 20-May-12 18:51pm    
Thank you, Shahin.
--SA
VJ Reddy 21-May-12 12:57pm    
Good answer. 5!
Sergey Alexandrovich Kryukov 21-May-12 14:10pm    
Thank you, VJ.
--SA

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900