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

How to move a borderless form?

11 views
Skip to first unread message

Terry

unread,
Aug 13, 2002, 4:56:09 PM8/13/02
to
Hi.

I need to move a borderless form, and have tried using the form's
mousedown/mousemove events. While I'm able to move the form, it flashes
like crazy, and it's not 100% accurate. Here's the code I'm using ... any
help would be appreciated. I'm sure I'm missing some very simple.

Private Sub frmViewer_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
blnMoving = True
origLoc.X = Me.Location.X
origLoc.Y = Me.Location.Y
origX = e.X
origY = e.Y
End Sub

Private Sub frmViewer_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If blnMoving = True Then
newloc.X = origLoc.X + (Screen.PrimaryScreen.Bounds.X - origX)
newloc.Y = origLoc.Y + (Screen.PrimaryScreen.Bounds.Y - origY)
If Me.Location.X <> newloc.X Or Me.Location.Y <> newloc.Y Then
Me.Location = newloc
End If
End If
End Sub

Private Sub frmViewer_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
blnMoving = False
newloc.X = newloc.X
newloc.Y = newloc.Y
Me.Location = newloc
End Sub


VBnet4Apps

unread,
Aug 13, 2002, 4:13:51 PM8/13/02
to
"Terry" <temi...@sasktel.net> wrote in message
news:uM4KsMwQCHA.3340@tkmsftngp12...

You might try this. It works for me without flicker.

http://www.avenuezx.com/VBnet4apps/tips/2.htm

----
VBnet4Apps
http://www.avenuezx.com/vbnet4apps/


Terry

unread,
Aug 13, 2002, 5:38:20 PM8/13/02
to
AWESOME!

THank you! Thank You! Thank You!

"VBnet4Apps" <VBnet4Ap...@avenuezx.com> wrote in message
news:#KecQXwQCHA.2520@tkmsftngp10...

Corrado Cavalli

unread,
Aug 13, 2002, 5:44:56 PM8/13/02
to
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
If m.Msg = &H84 Then
If m.Result.ToInt32 = 1 Then m.Result = New IntPtr(2)
End If
End Sub

HTH

--
Corrado Cavalli
UGIdotNET - http://www.ugidotnet.org


Terry

unread,
Aug 13, 2002, 7:24:12 PM8/13/02
to
Hi Corrado:

That's really cool code! Now if I could just understand why/how it works,
I'd really be happy!

Thanks much!
Terry
"Corrado Cavalli" <cor...@corrado.com> wrote in message
news:eCv$eLxQCHA.2632@tkmsftngp10...

Corrado Cavalli

unread,
Aug 13, 2002, 6:31:00 PM8/13/02
to
If simply looks for WM_NCHITTEST message (0x84), this message i sent from
windows to check what area is the cursor on.
If normal OS processing (done by MyBase.WndProc method) returns 1
(HT_CLIENT) meaning that cursor is on client area, it change it to 2
(HT_CAPTION) fooling Windows to believe that cursor is on caption area, this
enabled mouse dragging...

Terry

unread,
Aug 13, 2002, 8:02:39 PM8/13/02
to
Thanks Corrado ... you described this well!

"Corrado Cavalli" <cor...@corrado.com> wrote in message
news:OwhR7jxQCHA.3204@tkmsftngp13...
0 new messages