Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Moving objects in VB.NET

1 view
Skip to first unread message

vbguy

unread,
Dec 21, 2009, 9:47:37 PM12/21/09
to
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
[/code]

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

Cor Ligthert[MVP]

unread,
Dec 22, 2009, 3:14:24 AM12/22/09
to
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" <surfin...@yahoo.com> wrote in message
news:eec4ee81-af08-4099...@d21g2000yqn.googlegroups.com...

Alex Clark

unread,
Dec 22, 2009, 6:55:40 PM12/22/09
to
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[MVP]" <Notmyfi...@planet.nl> wrote in message
news:%23F2uH7t...@TK2MSFTNGP04.phx.gbl...

Cor Ligthert[MVP]

unread,
Dec 23, 2009, 1:48:32 PM12/23/09
to
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" <qua...@noemail.noemail> wrote in message
news:OSrpFJ2g...@TK2MSFTNGP02.phx.gbl...

Armin Zingler

unread,
Dec 23, 2009, 2:49:26 PM12/23/09
to
Cor Ligthert[MVP] schrieb:

> 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.

Like moving a file in Explorer. You can select it or drag it using an initial
threshold (see API function GetSystemMetric, SM_CXDRAG or SM_CYDRAG)

http://msdn.microsoft.com/en-us/library/ms724385%28VS.85%29.aspx

--
Armin


0 new messages