I'm trying to get my app to change the border style when I click a button. I want it to change from Sizable to Fixed Single... This doesn't work...
Me.BorderStyle = 1
And a way to work around that limitation is to create two forms, one with one border style, and one with the other. Use the buttons on each to do a me.hide and Other.Show.
You can do this by modifying window styles using GetWindowLong/SetWindowLong functions.
Start a new VB project, place a checkbox on the form and run the following code.
___
[tt]
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 SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const GWL_STYLE = -16
Const WS_THICKFRAME = &H40000
Const WS_MINIMIZEBOX = &H20000
Const WS_MAXIMIZEBOX = &H10000
Const WM_NCPAINT = &H85
Private Sub Check1_Click()
Dim dwStyle As Long
dwStyle = GetWindowLong(hwnd, GWL_STYLE)
If Check1.Value Then
dwStyle = dwStyle Or (WS_MAXIMIZEBOX Or WS_MINIMIZEBOX Or WS_THICKFRAME)
Else
dwStyle = dwStyle And Not (WS_MAXIMIZEBOX Or WS_MINIMIZEBOX Or WS_THICKFRAME)
End If
SetWindowLong hwnd, GWL_STYLE, dwStyle
SendMessage hwnd, WM_NCPAINT, 0, ByVal 0&
End Sub
Private Sub Form_Load()
Check1.Caption = "Sizable"
Check1.Value = 1
End Sub[/tt]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.