|
From: Patrick Weidener on 30 Jul 2008 07:45 I want to call the MouseDown event in a usercontrol when the DblClick event occurs. I don't want to use subclassing this time, I would need a quick solution. However, I cannot call MouseDown directly, because I don't know the position where the DblClick occured. I thought of using GetCursorPos and then somehow calculate the position where the dblclick occured on the control because GetCursorPos tells me where the mouse pointer is on the screen and not on the usercontrol. I guess that I need ClientToScreen to get the real coordinates, but I didn't find any samples for what I need.
From: expvb on 30 Jul 2008 08:19 "Patrick Weidener" <pawei_nospom(a)gmx.net> wrote in message news:ev%23menj8IHA.2332(a)TK2MSFTNGP03.phx.gbl... >I want to call the MouseDown event in a usercontrol when the DblClick event >occurs. > I don't want to use subclassing this time, I would need a quick solution. > However, I cannot call MouseDown directly, because I don't know the > position where the DblClick occured. > I thought of using GetCursorPos and then somehow calculate the position > where the dblclick occured on the control because GetCursorPos tells me > where the mouse pointer is on the screen and not on the usercontrol. > I guess that I need ClientToScreen to get the real coordinates, but I > didn't find any samples for what I need. You need ScreenToClient, and convert to twips or whatever scale mode you are using.
From: Larry Serflaten on 30 Jul 2008 08:25 "Patrick Weidener" <pawei_nospom(a)gmx.net> wrote > I want to call the MouseDown event in a usercontrol when the DblClick > event occurs. > I don't want to use subclassing this time, I would need a quick solution. > However, I cannot call MouseDown directly, because I don't know the > position where the DblClick occured. > I thought of using GetCursorPos and then somehow calculate the position > where the dblclick occured on the control because GetCursorPos tells me > where the mouse pointer is on the screen and not on the usercontrol. > I guess that I need ClientToScreen to get the real coordinates, but I > didn't find any samples for what I need. Add the code below to a new form and see what happens. See if that will give you a few ideas... LFS Private Sub Form_DblClick() Form_MouseDown -1, 0, 0, 0 End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Static mB%, mS%, mX!, mY! If Button >= 0 Then mB = Button mS = Shift mX = X mY = Y End If Debug.Print "Down at "; mX, mY End Sub
From: Patrick Weidener on 30 Jul 2008 09:42 Thanks to both of you. I'm still having problems distinguishing which button was pressed. I think my code is right, but GetAsynKeyState doesn't seem to be able to handle it correctly if clicks appear fast. For now, I'll just assume that the vbLeftButton is down. Private Sub UserControl_DblClick() Dim P As POINTAPI GetCursorPos P ScreenToClient UserControl.hwnd, P Dim X As Single Dim Y As Single X = P.X * Screen.TwipsPerPixelX Y = P.Y * Screen.TwipsPerPixelY Dim iButton% If GetAsyncKeyState(vbLeftButton) Then iButton = vbLeftButton ElseIf GetAsyncKeyState(vbRightButton) Then iButton = vbRightButton Else iButton = vbMiddleButton End If UserControl_MouseDown iButton, 0, X, Y End Sub
From: Dave O. on 30 Jul 2008 11:16
"Patrick Weidener" <pawei_nospom(a)gmx.net> wrote in message news:%23QFUuok8IHA.4924(a)TK2MSFTNGP02.phx.gbl... > Thanks to both of you. > > I'm still having problems distinguishing which button was pressed. I think > my code is right, but GetAsynKeyState doesn't seem to be able to handle it > correctly if clicks appear fast. For now, I'll just assume that the > vbLeftButton is down. > > Private Sub UserControl_DblClick() > > Dim P As POINTAPI > GetCursorPos P > > ScreenToClient UserControl.hwnd, P > > Dim X As Single > Dim Y As Single > > X = P.X * Screen.TwipsPerPixelX > Y = P.Y * Screen.TwipsPerPixelY > > Dim iButton% > > If GetAsyncKeyState(vbLeftButton) Then > iButton = vbLeftButton > ElseIf GetAsyncKeyState(vbRightButton) Then > iButton = vbRightButton > Else > iButton = vbMiddleButton > End If > > UserControl_MouseDown iButton, 0, X, Y > > End Sub I'm sure all that stuff above is not needed, make a few variables that are visible to the whole user control: something like a couple of longs lngX and lngY and a boolean bnLeft then in the user control Mouse_Down event you have: lngX = X lngY = Y bnLeft = (Button = 1) being public these values will be available in the Double_Click event thus rendering all that GetAsyncKeyState stuff superfluous. You can either use the ScreenToClient or just add the user control coordinates to the X & Y values Regards Dave O |