Can it be done?
At startup of app it is borderless. When I click on Command1 I have this
Form1.BorderStyle = 2 ' Make Sizable
but it doesn't change from borderless to sizable.
Printable View
Can it be done?
At startup of app it is borderless. When I click on Command1 I have this
Form1.BorderStyle = 2 ' Make Sizable
but it doesn't change from borderless to sizable.
It can only be done by using Windows APIs - no way without subclassing the form.
That sample is as good as it may get so definitely have a look at it.
There is another easier way. I got this idea from someone in VBF and modified it to make it 'near-perfect'. ;)
Only drawback is that, the Borderless form will be shown in the TaskBar.
vb Code:
Option Explicit Private Sub Form_Load() ' At design-time set the form as Sizable ' We'll make this form Borderless at runtime. ' Otherwise, the Close (X) button will not and the form will not be shown at taskbar ' when we change the border back to Sizable at runtime. Me.BorderStyle = 0 ' none Me.Caption = Me.Caption ' Forces VB to redraw titlebar, system menu and window border. End Sub Private Sub Command1_Click() Me.BorderStyle = 2 'sizable Me.Caption = Me.Caption ' Forces VB to redraw titlebar, system menu and window border. End Sub
This is what I use,
Code:Option Explicit
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 SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const GWL_STYLE As Long = (-16&)
Private Const WS_THICKFRAME As Long = &H40000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Sub Command1_Click()
' // Toggle Forms Borderstyle //
Call SetWindowLong(Me.hwnd, GWL_STYLE, GetWindowLong(Me.hwnd, GWL_STYLE) Xor _
(WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX))
Call SetWindowPos(Me.hwnd, 0&, 0&, 0&, 0&, 0&, SWP_NOMOVE Or _
SWP_NOSIZE Or SWP_NOZORDER Or SWP_FRAMECHANGED)
End Sub
So how to change it to swap between a borderless and a sizable toolwindow?
Have you looked at the sample project from the link I posted? :confused:
Yes I did and as a matter of fact I used pieces from it for my situation. Thanks alot for that link, by the way.
I was just wondering about Edgemeal's method just out of currosity.
Alright, it's nice to know you found some use for it. :afrog: