On Wed, 9 Jan 2002 12:57:37 -0500, "ran zhang"
Quote:
>I tried set borderstyle property of the form to 0 during run time, it doesnt
>seem to work... Then i tried to set
>Minbutton and Maxbutton, controlbox property in code, as Form1.Minbutton =
>False etc..
>it gives me an compiliation error.saying I can't modify them.
>I'm new to VB, what property are u allowed to set in code using
>'Object.property', and what arent???
>and why borderstyle property doesnt work if i set it to 0 to get rid of the
>titlebar of my Form1.??
He's a starting point to covercome VB's limitations. More work needs
to be done to support more controls. Hope it helps!
Graeme
-------------------------------------------------------------------------
1. Add a Class called cBorder. Then paste the following code into the
class:-
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_EXSTYLE As Long = (-20)
Private Const WS_EX_CLIENTEDGE As Long = &H200
Private Const WS_EX_STATICEDGE As Long = &H20000
Private Const SWP_NOMOVE As Long = &H2
Private Const SWP_NOSIZE As Long = &H1
Private Const SWP_NOZORDER As Long = &H4
Private Const SWP_NOACTIVATE As Long = &H10
Private Const SWP_FRAMECHANGED As Long = &H20
Public Enum eAppearance
[None] = 0
[Fixed Single] = 1
[Thin] = 2
End Enum
Private meAppearance As eAppearance
Private moControl As VB.Control
Public Property Get Appearance() As eAppearance
Appearance = meAppearance
End Property
Public Property Let Appearance(ByVal New_Appearance As eAppearance)
Dim lStyle As Long
If Not IsValid Then Exit Property
meAppearance = New_Appearance
'## Retrieve current style
lStyle = GetWindowLong(moControl.hWnd, GWL_EXSTYLE)
'## Toggle style flags
Select Case New_Appearance
Case [None]: lStyle = lStyle And Not WS_EX_CLIENTEDGE
And Not WS_EX_STATICEDGE
Case [Fixed Single]: lStyle = lStyle Or WS_EX_CLIENTEDGE And
Not WS_EX_STATICEDGE
Case [Thin]: lStyle = lStyle And Not WS_EX_CLIENTEDGE
Or WS_EX_STATICEDGE
End Select
'## Apply changes
SetWindowLong moControl.hWnd, GWL_EXSTYLE, lStyle
SetWindowPos moControl.hWnd, 0, 0, 0, 0, 0, SWP_NOACTIVATE Or
SWP_NOZORDER Or SWP_FRAMECHANGED Or _
SWP_NOSIZE Or SWP_NOMOVE
End Property
Public Sub Init(Obj As VB.Control)
Set moControl = Obj
End Sub
Private Function IsValid() As Boolean
Debug.Print TypeName(moControl)
IsValid =
(InStr("TextBox*ListBox*ListView*TreeView*PictureBox*Slider*",
TypeName(moControl) + "*") > 0)
End Function
Private Sub Class_Terminate()
Set moControl = Nothing
End Sub
2. Add a series of controls onto a form. Then add the following code
to the form:
Private moBorder() As cBorder
Private Sub Form_Load()
Dim Obj As VB.Control
Dim iCount As Integer
ReDim moBorder(0 To Me.Controls.Count - 1)
For Each Obj In Me.Controls
Set moBorder(iCount) = New cBorder
With moBorder(iCount)
.Init Obj
.Appearance = [Thin]
End With
iCount = iCount + 1
Next
End Sub
3. Run Project and only those controls that can be modified
successfully (those that I've tested) will be modified!