Obtain Position/Button of mouse click on DoubleClick event

后端 未结 3 410
野趣味
野趣味 2021-01-18 11:04

Is there a method to obtain the (x, y) coordinates of the mouse cursor in a controls DoubleClick event?

As far as I can tell, the position has to be obtained from th

3条回答
  •  醉话见心
    2021-01-18 11:30

    Note: As danbruc pointed out, this won't work on a UserControl, because e is not a MouseEventArgs. Also note that not all controls will even give you a DoubleClick event - for example, a Button will just send you two Click events.

      private void Form1_DoubleClick(object sender, EventArgs e)
       {
           MouseEventArgs me = e as MouseEventArgs;
    
           MouseButtons buttonPushed = me.Button;
           int xPos = me.X;
           int yPos = me.Y;
       }
    

    Gets x,y relative to the form..

    Also has the left or right button in MouseEventArgs.

提交回复
热议问题