MouseDown Event

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JJ

    #1

    MouseDown Event

    Hi All,

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

    pictureBox.Mous eDown += new
    System.WinForms .MouseEventHand ler(pictureBox_ MouseDown)

    Then

    Create Event


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

    // code etc....

    }

    Thanks,

    JJ


  • Jerome Terry

    #2
    Re: MouseDown Event

    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_Mous eDown, but your function is called pictureBox_OnMo useDown.
    Is this a typo?

    The code should look like the following, assuming that pictureBox and
    pictureBox_Mous eDown 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_Mous eDown will get executed.
    pictureBox.Mous eDown += new MouseEventHandl er(this.picture Box_MouseDown)

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

    Hope this helps,
    Jerome


    "JJ" <jmraz@bellatla ntic.net> wrote in message
    news:uSt5sb1SDH A.2196@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Hi All,
    >
    > I need to create a MouseDown event for a picture box . Am I doing the
    > following right?
    >
    > pictureBox.Mous eDown += new
    > System.WinForms .MouseEventHand ler(pictureBox_ MouseDown)
    >
    > Then
    >
    > Create Event
    >
    >
    > public void pictureBox_OnMo useDown(object sender,
    > System.WinForms .MouseEventArgs e)
    > {
    >
    > // code etc....
    >
    > }
    >
    > Thanks,
    >
    > JJ
    >
    >[/color]


    Comment

    • Christian

      #3
      Re: MouseDown Event


      [color=blue]
      > pictureBox.Mous eDown += new
      > System.WinForms .MouseEventHand ler(pictureBox_ MouseDown)
      >
      >
      > public void pictureBox_OnMo useDown(object sender,
      > System.WinForms .MouseEventArgs e)[/color]
      // No! use the same name:
      pictureBox_Mous eDown


      Comment

      Working...