Moving objects in VB.NET

V

vbguy

I am using this code to move a button at run time.

Code:
If e.Button = Windows.Forms.MouseButtons.Left Then
Button1.Capture = False
Dim msg As Message = _
Message.Create(Button1.Handle, WM_NCLBUTTONDOWN, _
New IntPtr(HTCAPTION), IntPtr.Zero)
Me.DefWndProc(msg)
End If

Everything works as planned, however, I can not click on the button.
It basically freezes the click event and is only movable.

I was told to confirm the location on the mouse up event, but do not
exactly know what that means.

Can anyone help me on this subject?


Thanks in advance
 
C

Cor Ligthert[MVP]

What do you mean by move?

The location, you use the left property (the property meant for its left
location to something at least I don't understand)

Moving a location 10 points to the right in its parent container, you can
simply do with.

Button1.left = Button1.left+10

Properties to do this are location (which uses points), left and top

Success

Cor
 
A

Alex Clark

Cor,

I believe he's trying to move the button by dragging it with the mouse, and
is using window messages to simulate a taskbar drag but on the button itself
rather than a window.

In answer to vbguy's question:

Have you tried calling ReleaseCapture with an hWnd of 0 afterwards?

Also, you're sending a message to the button indicating the left mouse
button was pressed on it's non-client area. Have you sent a corresponding
WM_NCLBUTTONUP message once the mouse button is released?

HTH,
Alex



Cor Ligthert said:
What do you mean by move?

The location, you use the left property (the property meant for its left
location to something at least I don't understand)

Moving a location 10 points to the right in its parent container, you can
simply do with.

Button1.left = Button1.left+10

Properties to do this are location (which uses points), left and top

Success

Cor

vbguy said:
I am using this code to move a button at run time.

Code:
If e.Button = Windows.Forms.MouseButtons.Left Then
Button1.Capture = False
Dim msg As Message = _
Message.Create(Button1.Handle, WM_NCLBUTTONDOWN, _
New IntPtr(HTCAPTION), IntPtr.Zero)
Me.DefWndProc(msg)
End If

Everything works as planned, however, I can not click on the button.
It basically freezes the click event and is only movable.

I was told to confirm the location on the mouse up event, but do not
exactly know what that means.

Can anyone help me on this subject?


Thanks in advance
 
C

Cor Ligthert[MVP]

Alex,

Seems to me very difficult to do, to drag a button by a mouse, how do you
know that it was not a click.

But you never know what humans are able to think of they need to do

:)

Cor

Alex Clark said:
Cor,

I believe he's trying to move the button by dragging it with the mouse,
and is using window messages to simulate a taskbar drag but on the button
itself rather than a window.

In answer to vbguy's question:

Have you tried calling ReleaseCapture with an hWnd of 0 afterwards?

Also, you're sending a message to the button indicating the left mouse
button was pressed on it's non-client area. Have you sent a corresponding
WM_NCLBUTTONUP message once the mouse button is released?

HTH,
Alex



Cor Ligthert said:
What do you mean by move?

The location, you use the left property (the property meant for its left
location to something at least I don't understand)

Moving a location 10 points to the right in its parent container, you can
simply do with.

Button1.left = Button1.left+10

Properties to do this are location (which uses points), left and top

Success

Cor

vbguy said:
I am using this code to move a button at run time.

Code:
If e.Button = Windows.Forms.MouseButtons.Left Then
Button1.Capture = False
Dim msg As Message = _
Message.Create(Button1.Handle, WM_NCLBUTTONDOWN, _
New IntPtr(HTCAPTION), IntPtr.Zero)
Me.DefWndProc(msg)
End If

Everything works as planned, however, I can not click on the button.
It basically freezes the click event and is only movable.

I was told to confirm the location on the mouse up event, but do not
exactly know what that means.

Can anyone help me on this subject?


Thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top