locked
Custom Control RRS feed

  • Question

  • I have two questions… 

     

    First, I found a attribute for the class that opens the class in code view when double clicked in the solution explorer.  I have misplaced the snippet and I have not been able to relocate the attribute on the web.

     

    Second, I would like to update the Registry Attributes Value property in the Properties Windows when the Text property changes.  (Design and Runtime)

     

    Imports System.ComponentModel

    Imports Microsoft.Win32

     

    #Region "Registry TextBox Control"

    <ToolboxBitmap(GetType(TextBox))> _

    Public Class RTextBox

        Inherits System.Windows.Forms.TextBox

     

        Private m_RegistryAttributes As New RegistryAttributes

     

        Public Sub New()

            MyBase.New()

        End Sub

     

        <TypeConverter(GetType(RegistryAttributesTypeConverter))> _

        Property RegistryAttributes() As RegistryAttributes

            Get

                Return m_RegistryAttributes

            End Get

            Set(ByVal Value As RegistryAttributes)

                m_RegistryAttributes = Value

            End Set

        End Property

     

        Private Sub RTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.TextChanged

            m_RegistryAttributes.RegistryValue = Me.Text

        End Sub

     

    #Region "Registry Attributes Type Converter"

     

        ' The TypeConverter for the RegistryAttributes property

        Private Class RegistryAttributesTypeConverter

            Inherits TypeConverter

     

            Public Overloads Overrides Function GetProperties(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal value As Object, ByVal attributes() As System.Attribute) As System.ComponentModel.PropertyDescriptorCollection

                Return TypeDescriptor.GetProperties(GetType(RegistryAttributes))

            End Function

     

            Public Overloads Overrides Function GetPropertiesSupported(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean

                Return True

            End Function

     

        End Class

     

    #End Region

     

    End Class

     

    #End Region

     

    #Region "RegistryAttributes Class"

     

    Public Class RegistryAttributes

     

        Private mRoot As Microsoft.Win32.RegistryHive

        Private mKey As String

        Private mValue As String

     

        Public Sub New()

            mRoot = RegistryHive.LocalMachine

            mKey = ""

            mValue = ""

        End Sub

     

        Public Property Root() As Microsoft.Win32.RegistryHive

     

            Get

                Return mRoot

            End Get

     

            Set(ByVal Value As Microsoft.Win32.RegistryHive)

                mRoot = Value

            End Set

     

        End Property

     

        Friend WriteOnly Property RegistryKey() As String

            Set(ByVal Value As String)

                mKey = Value

            End Set

        End Property

     

        Public ReadOnly Property Key()

            Get

                Return mKey

            End Get

        End Property

     

        Friend WriteOnly Property RegistryValue() As String

            Set(ByVal Value As String)

                mValue = Value

            End Set

        End Property

     

        Public ReadOnly Property Value()

            Get

                Return mValue

            End Get

        End Property

     

        ' Override ToString

        Public Overrides Function ToString() As String

            Return "(Registry Attributes)"

        End Function

     

    End Class

     

    #End Region

    Friday, February 24, 2006 7:52 PM

Answers

  • First question:

    The attribute is called DesignerCategory("Code")

    Second question:

    I'm not sure exactly what problem you are having.  But if you want proper undo support you will need to notify the designer that a certain property has changed.

    You can do this if you create your own designer, subscribe on TextChanged and add the following:

    IComponentChangeService icc = (IComponentChangeService)GetService(typeof(IComponentChangeService)

    icc.OnComponentChanged(this.Component, TypeDescriptor.GetProperties(this.Component)["RegistryAttribute"], oldvalue, newvalue);

    You can also change the value by using a PropertyDescriptor in your control -- which will trigger the right designer behavior.

     

    Monday, March 6, 2006 3:54 AM