MouseDown Event

J

JJ

Hi All,

I need to create a MouseDown event for a picture box . Am I doing the
following right?

pictureBox.MouseDown += new
System.WinForms.MouseEventHandler(pictureBox_MouseDown)

Then

Create Event


public void pictureBox_OnMouseDown(object sender,
System.WinForms.MouseEventArgs e)
{

// code etc....

}

Thanks,

JJ
 
C

Christian

pictureBox.MouseDown += new
System.WinForms.MouseEventHandler(pictureBox_MouseDown)


public void pictureBox_OnMouseDown(object sender,
System.WinForms.MouseEventArgs e)
// No! use the same name:
pictureBox_MouseDown
 
J

Jerome Terry

What do you mean by, " Then Create Event"? Your code is ambiguous. When
you add the event handler to the pictureBox, you pass in the function
pictureBox_MouseDown, but your function is called pictureBox_OnMouseDown.
Is this a typo?

The code should look like the following, assuming that pictureBox and
pictureBox_MouseDown exist in the same class:

// in initialization (perhaps in the constructor) add event handler to the
PictureBox
// This actually creates the event delegate and adds it to the list of
MouseDown delegates for pictureBox.
// When the MouseDown event is raised by pictureBox(i.e. when you press a
mouse button on the pictureBox),
// the function pictureBox_MouseDown will get executed.
pictureBox.MouseDown += new MouseEventHandler(this.pictureBox_MouseDown)

// the MouseDown event handler
private void pictureBox_MouseDown(object sender, MouseEventArgs e)
{
// do whatever you need to do.
}

Hope this helps,
Jerome
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top