Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Border style to change during app operation 2

Status
Not open for further replies.

mark01

Technical User
Jan 17, 2001
600
US
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

Any Suggestions?

Thanks
 
From MSDN

"Returns or sets the border style for an object. For the Form object and the TextBox control, read-only at run time."

As it says, this is read-only at run time so it is no wonder it is not working.

Andy
 
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.

HTH

Bob
 
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]
 
Thank you very much for that wonderful code. That is exactly what I needed...

Thanks again!
 
Very cool. I'm weak on API stuff, and that's very elegant. Another star. :)

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top