borderstyle property 
Author Message
 borderstyle property

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



Mon, 28 Jun 2004 01:57:37 GMT  
 borderstyle property
Ran Zhang,

You can't change the BorderStyle property of a form at run
time, because the BorderStyle proeprty is READ ONLY at run
time, like other properties (minbutton, maxbutton, etc,
etc.).

In all controls, there are:

- Properties that can be set in desing time, and run time.
- Properties that are only available at run time
(ej, "Value" property of a ProgressBar control).
- Properties that are READ/WRITE at desing time, but READ
ONLY at run time (you are here)

If you want to make a form with no border on it, you
should set BorderStyle to 0 at design time. If you wish to
change this border at runtime, maybe you can try with API
functions, but that's a bit more complicated.

Hope it helps!
Nautilus

Quote:
>-----Original Message-----
>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.??

>.



Mon, 28 Jun 2004 02:38:22 GMT  
 borderstyle property
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!



Mon, 28 Jun 2004 16:19:16 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. TextBox .BorderStyle property at run-time

2. Setting BorderStyle property

3. Help: BorderStyle property don't work for subclassed Edit control

4. : BorderStyle property of text control

5. BorderStyle property for VB.Form

6. Mapping BorderStyle property

7. Changing Form's BorderStyle property at run time but before form is loaded

8. Bug? Problem w/ MenuControl and Form BorderStyle property....

9. DateTime Picker BorderStyle

10. TextBox BorderStyle

11. Setting BorderStyle fies Enter event

12. Form BorderStyle and Icon

 

 
Powered by phpBB® Forum Software