Re: Problem with Mousemove event and moving button
Don_at_home.com
Date: 07/21/04
- Next message: Gale Green: "Re: Problem with Mousemove event and moving button"
- Previous message: anonymous_at_discussions.microsoft.com: "Can you go to this newsgroup via a web interface ?"
- In reply to: ohaya: "Problem with Mousemove event and moving button"
- Next in thread: Gale Green: "Re: Problem with Mousemove event and moving button"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 21 Jul 2004 19:06:35 GMT
On Wed, 21 Jul 2004 11:52:49 -0700, "ohaya"
<anonymous@discussions.microsoft.com> wrote:
>Hi,
>
>I'm writing a program where the user can place new
>(Command) buttons on the form by clicking on the form, and
>where they can then move the button by clicking on it,
>then dragging it.
>
>I've been able to get the create new button part working,
>but in order to determine where to put the button on the
>Form, I have a Form_Click event that saves the X and Y
>values off to mouse_X and mouse_Y.
>
>Then in my CommandX_Mousedown event, I set a flag
>(indicating that the user has clicked on the button, and
>in the CommandX_Mousemove event, I do the .Move X,Y to
>move the button as the mouse is dragged (with the button
>still down).
>
>This is kind of working, but about 1/2 the time, when I
>click down on a Command button, and then drag the mouse,
>and then release the mouse button, the Command button
>jumps to some (somewhat random) location on the form.
>
>Does anyone have any idea what might be causing this? I
>would have wanted not to use the Form_Mousemove, but I
>couldn't find any other way to capture the X,Y of the
>mouse pointer when it was clicked on the Form.
>
>Thanks,
>Jim
Easiest way to move any control that has a .hwnd property
Start a new project and add a command button and the code below...
Option Explicit
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal
hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Sub ReleaseCapture Lib "User32" ()
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Sub command1_MouseMove(Button As Integer, Shift As Integer, X As Single,
Y As Single)
Dim lRtn As Long
If Button = 1 Then
Call ReleaseCapture
lRtn = SendMessage(Command1.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End If
End Sub
Have a good day...
Don
- Next message: Gale Green: "Re: Problem with Mousemove event and moving button"
- Previous message: anonymous_at_discussions.microsoft.com: "Can you go to this newsgroup via a web interface ?"
- In reply to: ohaya: "Problem with Mousemove event and moving button"
- Next in thread: Gale Green: "Re: Problem with Mousemove event and moving button"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|