|
-
Sep 21st, 2009, 05:59 PM
#1
Thread Starter
Hyperactive Member
Move borderless form.
I already got the move part, that's easy, what I'm having trouble with is when I click on the form and try to move it, it shifts a little, that is really annoying, I just want it to be smooth. I want it to be as if I'm moving the form from the title bar. Here's my code.
vb Code:
Public Class Form1
Dim Down As Boolean = False
Dim Local1 As Point
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
Down = True
Local1 = e.Location
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If Down = True Then
Me.Location = MousePosition - Local1
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
Down = False
End Sub
End Class
-
Sep 21st, 2009, 06:05 PM
#2
Re: Move borderless form.
Add this and take out all of your moving code:
vb.net Code:
Protected Overrides Sub WndProc(ByRef e As Message)
MyBase.WndProc(e)
If e.Message = &H84 AndAlso e.Result = &H1 Then e.Result = &H2
End Sub
-
Sep 21st, 2009, 06:12 PM
#3
Thread Starter
Hyperactive Member
Re: Move borderless form.
 Originally Posted by minitech
Add this and take out all of your moving code:
vb.net Code:
Protected Overrides Sub WndProc(ByRef e As Message)
MyBase.WndProc(e)
If e.Message = &H84 AndAlso e.Result = &H1 Then e.Result = &H2
End Sub
That doesn't really want to work for me. e.message is underlined.
-
Sep 21st, 2009, 06:20 PM
#4
Re: Move borderless form.
 Originally Posted by DerekM
That doesn't really want to work for me. e.message is underlined.
Change it to e.Msg. Sorry!
-
Sep 21st, 2009, 06:25 PM
#5
Re: Move borderless form.
 Originally Posted by minitech
Add this and take out all of your moving code:
vb.net Code:
Protected Overrides Sub WndProc(ByRef e As Message)
MyBase.WndProc(e)
If e.Message = &H84 AndAlso e.Result = &H1 Then e.Result = &H2
End Sub
Not so sure about those magic numbers. What are &H84, &H1 and &H2?
-
Sep 21st, 2009, 06:29 PM
#6
Re: Move borderless form.
&H84: Some sort of mousedown
&H1 result of &H84: The client area of a window.
&H2 result of &H84: The title bar of a window.
You're telling the windows message system that if the mouse is down on the client area, it's actually on the nonexistant title bar. 
Normally people use named constants, but I think it's unneccessary.
-
Sep 21st, 2009, 06:32 PM
#7
Re: Move borderless form.
 Originally Posted by minitech
Normally people use named constants, but I think it's unneccessary.
Thats fine so long as no one else will ever need to work with your code. You should always use named constants if you are writing code that someone else will need to look at (like if you're using your code to illustrate a mechanism on a forum!)
-
Sep 21st, 2009, 06:45 PM
#8
Thread Starter
Hyperactive Member
Re: Move borderless form.
 Originally Posted by minitech
Change it to e.Msg. Sorry!
Works great! But how could I apply this to any control?
-
Sep 21st, 2009, 07:25 PM
#9
Re: Move borderless form.
 Originally Posted by minitech
Normally people use named constants, but I think it's unneccessary.
I used to think so too, but then I had to edit 2 year old code that I wrote... it changed my way of thinking PDQ!
Last edited by kebo; Sep 21st, 2009 at 08:06 PM.
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Sep 22nd, 2009, 06:09 AM
#10
Re: Move borderless form.
Take a look at my signature, there's a codebank submission on doing what you want to do. Instead of only moving, there is also resizing, including a cursor that changes to the correct resizing cursor.
It uses more or less the same code as minitech's code; it makes the window think the user is moving it via the title bar, instead of you manually setting the Location each time. This way it is much smoother, and there is no danger of 'letting the form slip' (if you use the manual way and move too fast, the form will not be able to update quickly enough or something and you will lose it).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|