views:

280

answers:

1

Hello,

In our IDE, for example, Visual Studio, if we display the properties of a System.Windows.Forms.Button control, we see some properties that expose anoter set of properties. For example: FlatAppearance, Font, Location, Margin, etcetera.

I would like to do something similar in a custom control.

I know the code behind is wrong, but here is an example of what I´m trying to do:

Public Class StateOfMyCustomControl

    Public Enum EnumVisibility
        Visible
        NonVisible
    End Enum

    Public Enum EnumEventManagement
        Automatic
        Manual
    End Enum

    Private mAssociatedControl As MyCustomControl
    Private mVisibility As EnumVisibility
    Private mEventManagement As EnumEventManagement

    Public Sub New(ByVal AssociatedControl As MyCustomControl)
        mAssociatedControl = AssociatedControl
    End Sub

    Public Property Visibility() As EnumVisibility
        Get
            Return mVisibility
        End Get
        Set(ByVal value As EnumVisibility)

            mVisibility = value

            mAssociatedControl.Visible = False
            If mVisibility = EnumVisibility.Visible Then
                mAssociatedControl.Visible = True
            End If

        End Set
    End Property

    Public Property EventManagement() As EnumEventManagement
        Get
            Return mEventManagement
        End Get
        Set(ByVal value As EnumEventManagement)
            mEventManagement = value
        End Set
    End Property

End Class

Public Class MyCustomControl

    ' ...

    Private mState As StateOfMyCustomControl

    Public Sub New()
        mState = New StateOfMyCustomControl(Me)
    End Sub

    Public Property State() As StateOfMyCustomControl
        Get
            Return mState
        End Get
        Set(ByVal value As StateOfMyCustomControl)
            mState = value
        End Set
    End Property

    ' ...

End Class

In my IDE, in the properties window of my custom control, I would like to see my property State, with the possibility of display it to set the properties Visibility and EventManagement.

Thanks very much

+2  A: 

You need to tell it to use ExpandableObjectConverter (or a custom converter) for StateOfMyCustomControl. In C#, this is:

[TypeConverter(typeof(ExpandableObjectConverter))]
public class StateOfMyCustomControl {...}

However you apply attributes in VB, do that ;-p

Possibly:

<TypeConverter(GetType(ExpandableObjectConverter))> _
Public Class StateOfMyCustomControl
...
Marc Gravell
Hi Marc, I´ve imported System.ComponentModel namespace to use TypeConverter attribute. I've proved it and works fine. Thanks very much!
Javier Morillo