I have a form with no border (and has to stay that way). But I want to be able to move the form around by clicking on it and dragging it around or something, and it should also show up in the taskbar, which it doesn't when borderstyle = 0.
Thanks.
Printable View
I have a form with no border (and has to stay that way). But I want to be able to move the form around by clicking on it and dragging it around or something, and it should also show up in the taskbar, which it doesn't when borderstyle = 0.
Thanks.
There isn't any conventional way to accomplish this task so use of some api will be in order:
VB Code:
Private Const GWL_STYLE = (-16) Private Const WS_SYSMENU = &H80000 Private Const WS_MINIMIZEBOX = &H20000 Private Const WM_NCLBUTTONDOWN = &HA1 Private Const HTCAPTION = 2 Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Sub Form_Load() '======================= Dim lStyle As Long 'ensure taskbar icon visibility lStyle = GetWindowLong(hwnd, GWL_STYLE) Or WS_SYSMENU Or WS_MINIMIZEBOX SetWindowLong hwnd, GWL_STYLE, lStyle End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then ReleaseCapture SendMessageLong Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0& End If End Sub
Thanks Works Great!
Cool! :wave:
Can you help me how to put this in my form?
What kind of help do you expect? :confused: I don't suppose you're asking someone to copy/paste code sample for you, do you?
Rhino,just in curious i m asking, is this method doing the right job?Quote:
There isn't any conventional way to accomplish this task so use of some api will be in order:
and we can chage the ShowInTaskBar property at design time according to the need,Code:Dim x1 As Single, y1 As Single
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
x1 = X
y1 = Y
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Me.Left = Me.Left - (x1 - X)
Me.Top = Me.Top - (y1 - Y)
End If
End Sub
am i right rhino?
edited: just code changed abt left button click
Hey Seenu_1st,
You are right and I've been using this code since last three years... Me and my friend made it on our own :) The problem with this code is that the form is always visible while moving (even if you have a theme that show only borders while moving a window). The ShowInTaskbar can be set to true in design time but it won't be able to minimize/restore/close/maximize as a normal program in taskbar does... Like if you click on it's taskbar icon, it is minimized and if you right click, you find various options (close/maximize, etc.)
ATH, thanks for the info, so the diff is taskbar proprties.
Rhino, i got it.