
BorderStyle property for VB.Form
Hi Marc. Give this a try:
'place the following code in a module
Public PreserveFormStyle As Long
Public Const GWL_STYLE = (-16)
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA"
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA"
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal X
As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal
bRepaint As Long) As Long
'window styles for get/set window long
Public Const WS_CAPTION = &HC00000
Public Const WS_OVERLAPPED = &H0&
Public Const WS_THICKFRAME = &H40000
'call this first
Public Sub MakeBorderstyle_vbBSNone()
Dim L As Long
L = GetWindowLong(Me.hwnd, GWL_STYLE)
PreserveFormStyle = L
L = L And Not (WS_OVERLAPPED Or WS_CAPTION Or _
WS_THICKFRAME)
Call SetWindowLong(Me.hwnd, GWL_STYLE, L)
Call MoveWindow(Me.hwnd, _
Me.ScaleX(Me.Left, vbTwips, vbPixels), _
Me.ScaleY(Me.Top, vbTwips, vbPixels), _
Me.ScaleX(Me.Width - 10, vbTwips, vbPixels), _
Me.ScaleY(Me.Height - 10, vbTwips, vbPixels), True)
End Sub
'to set it back to sizable
Public Sub MakeBorderstyle_vbSizable()
Dim L As Long
L = GetWindowLong(Me.hwnd, GWL_STYLE)
Call SetWindowLong(Me.hwnd, _
GWL_STYLE, PreserveFormStyle)
Call MoveWindow(Me.hwnd, _
Me.ScaleX(Me.Left, vbTwips, vbPixels), _
Me.ScaleY(Me.Top, vbTwips, vbPixels), _
Me.ScaleX(Me.Width + 10, vbTwips, vbPixels), _
Me.ScaleY(Me.Height + 10, vbTwips, vbPixels), True)
End Sub
hth
galen
Quote:
>One of the properties VB5 VB.Form object is BorderStyle.
>In custom UserControl that I have built I need to maintain two similar
>VB.Form objects (one with BorderStyle=vbBSNone and the other with
>BorderStyle=vbSizable) because BorderStyle is READ-ONLY at run time.
>It seems stupid to duplicate code and maintain two graphical forms, but I
>haven't found another way.
>Someone have a solution ?
>Did VB6 will allow to change BorderStyle value at run time ?
>Regards,