Moving window without title bar

Camus

Active member
Joined
Oct 4, 2007
Messages
28
Programming Experience
Beginner
On the program I have created I have set FormBorderSyle to 'None', as a result I cannot drag the window of my program around.

Is there another way I can do this without a title bar?

I have found some references to this on the internet but I'm a beginner at this and so don't know how to implement it in my code.
 
I found this code -


VB.NET:
Option Explicit 
Dim XPos As Long, YPos As Long 

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) 
    XPos = X 
    YPos = Y 
End Sub 

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) 
    If Button = vbLeftButton Then 
        Me.Left = Me.Left - (XPos - X) 
        Me.Top = Me.Top - (YPos - Y) 
    End If 
End Sub



But when i paste it in, i get a couple of messages such as 'vbLeftButton is not declared'.
How do i declare it?
These questions may seem stupid but I'm just learning as I go along.
 
that's because it's vb6 code, the subs for Form_MouseDown and Form_MouseMove have changed quite a bit

you'll need to select the MouseDown and MouseMove event from the dropdown in codeview in the IDE to get the corrects subs for those events, then place the code into each event and move on from there
 
I couldn't find what you were describing, could you explain that again please?

I'm using Visual Basic Express.
 
try this, it works for me...

VB.NET:
Public Class Form1
    Private MouseDownLoc As Point

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        MouseDownLoc.X = e.X
        MouseDownLoc.Y = e.Y
End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        
If e.Button = Windows.Forms.MouseButtons.Left Then
            Me.Left += e.X - MouseDownLoc.X
            Me.Top += e.Y - MouseDownLoc.Y
End If
End Sub
end class
 
Hey, I tried that and had these error messages -

Event 'Mousedown' cannot be found.
Event 'Mousemove' cannot be found.
'Left' is not a member of 'WindowsApplication1.
'Top' is not a member of 'WindowsApplication1.

Do you know what I'm doing wrong? Juggalo said before that I was trying to use VB6 code, is that the same here? I'm using visual basic express.
 
this is the way i figured out myself

Put this code in to a module like so:-
VB.NET:
Module modMove

#Region "Const's and Functions"

    Public Const WM_NCLBUTTONDOWN As Integer = &HA1
    Public Const HTCAPTION As Integer = &H2
    Declare Function ReleaseCapture Lib "user32.dll" () As Int32
    Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32

#End Region

#Region "Subs"

    Public Sub wMove(ByVal hand As String)
        ReleaseCapture()
        SendMessage(hand, WM_NCLBUTTONDOWN, HTCAPTION, 0)
    End Sub

#End Region

End Module

to use the code, use the MouseDown event for any object on your form or the form itself, like so:-
VB.NET:
    Private Sub lblTitle_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lblTitle.MouseDown
        wMove(Me.Handle)
    End Sub

i know this code works in VB 2003, 2005 and 2008. this is one of the codes i have kept through out

you can download the module attached (beware there are no comments)
 

Attachments

  • modMove.zip
    402 bytes · Views: 39
Last edited:
Back
Top