By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,616 Members | 1,618 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,616 IT Pros & Developers. It's quick & easy.

MouseDown Event

P: n/a
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_Mouse Down)

Then

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

// code etc....

}

Thanks,

JJ
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
"JJ" <jm***@bellatlantic.net> wrote in message
news:uS**************@TK2MSFTNGP12.phx.gbl...
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_Mouse Down)

Then

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

// code etc....

}

Thanks,

JJ

Nov 13 '05 #2

P: n/a

pictureBox.MouseDown += new
System.WinForms.MouseEventHandler(pictureBox_Mouse Down)
public void pictureBox_OnMouseDown(object sender,
System.WinForms.MouseEventArgs e)

// No! use the same name:
pictureBox_MouseDown
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.