Graphics Query

  • Thread starter Thread starter Poornima
  • Start date Start date
P

Poornima

Hello,

I have a mouse click event in which i need to draw a line if the mouse
was clicked within specified co-ordinates.I wrote the following code

private void Form1_MouseClick(object sender, MouseEventArgs
e,PaintEventArgs pe)
{
Graphics mclkDl = pe.Graphics;
Pen dashPen = new Pen(Color.Gray, 1);

tbMouseX.Text = "The X-cordinate is " + MousePosition.X;
tbMouseY.Text = "The Y-cordinate is " + MousePosition.Y;
nMouseX = MousePosition.X;
nMouseY = MousePosition.Y;

if(nMouseX >= 50 && nMouseY == 169)
mclkDl.DrawLine(dashPen, 50, 80, 169, 80);

}

but it gave an error saying

"No Overload for form1_MouseClick matches delegate
'System.Windows.Forms.MouseEventHandler'"

Can any one of you please tell me whts wrong in the code

Thanks In Advance
Poornima
 
Hi Poornima,
the MouseEventHandler delegate does not take the PaintEventArgs parameter
you are trying to pass in the Form1_MouseClick method signature. If you want
to draw on the mouse click you are going to need to create a Graphics object
and create a class level field that you can use to draw to.

Mark.
 
Mark said:
Hi Poornima,
the MouseEventHandler delegate does not take the PaintEventArgs parameter
you are trying to pass in the Form1_MouseClick method signature. If you want
to draw on the mouse click you are going to need to create a Graphics object
and create a class level field that you can use to draw to.

Mark.
Thank you but can you explain me with an example code because iam new
to C# .
 
Back
Top