Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Code Snippet: System.Component Model Namespace
 

Code Snippet: System.Component Model Namespace

This is simple stuff but I had to search the web for days before I figured out how to document my UserControls and Components properly. This Public Property will show up in the Properties dialog box under the "Ape Functionality" category, with it's own description down at the bottom of the property box, and a default color that isn't bolded (meaning a non-default setting). All these things were important to me since I wanted my components to look and feel as professional (like MS stuff) as possible. Maybe you will as well.
Imports System.ComponentModel

Public Class
        Inherits System.Windows.Forms.TextBox

        Private mcolFocusColor As Color = Color.Turquoise
        <Category("Ape Functionality"), DefaultValue(GetType(Color), "Turquoise"), _
        Description("Change background to this color while it has the focus.")> _
        Public Property FocusColor() As Color
            Get
                Return mcolFocusColor
            End Get
            Set(ByVal Value As Color)
                mcolFocusColor = Value
            End Set
        End Property

        ' . . . reamains of class deleted for brevity 
MigrationUser 1  Thursday, August 07, 2003 1:56 PM
A comment on DefaultValue . . . 

The DefaultValue will work for most simple types (strings, etc), but, if you want something more complex, like a Font, then the ShouldSerializeXXXX and ResetXXXX technique should be used:

        <Category("Appearance"), Description("Controls the font of the items represented in the trees")> _
        Public Property TreeviewFont() As Font
            Get
                 'yadda yadda
            End Get
            Set(ByVal Value As Font)
                 'yadda yadda
            End Set
        End Property

        Private Function ShouldSerializeTreeviewFont() As Boolean
            Return Not TreeviewFont.Equals(New Font("Microsoft Sans Serif", 8.25))
        End Function

        Private Sub ResetTreeviewFont()
            TreeviewFont = New Font("Microsoft Sans Serif", 8.25)
        End Sub
MigrationUser 1  Thursday, August 07, 2003 2:32 PM
You know . . . I DID have that problem but didn't think to ask this group. Thanks a lot! Also, I just purchased WROX's "Visual Basic .NET Serialization Handbook" so I could get a better grip on serialization in general. I'm still at serialization dummy level but not for long.
MigrationUser 1  Thursday, August 07, 2003 4:53 PM

You can use google to search for other answers

Custom Search

More Threads

• bindingcontrol datagridview in tabcontrol column visible strange problem :((
• Inherited ControlDesigner
• ES_NUMBER and it's related error message
• designer for custom webcontrol
• Datagrid Combobox
• whats the best pattern to avoid deserialisation of usercontrol properties overwriting one another?
• Access Button / Form from Inherited Control
• Using Windows Forms: Writing & Developing A VB 2005 Express Program "MyGame"-It ran but no errors & no results!!??
• How pass current assembly to custom typeconverter to realize typelistconverter in propertygrid for my control?
• Implement Drag & Drop and Mouse Events