[Implementing the ASP. Net Control as day18] modifying the set property Editor

Source: Internet
Author: User

In the previous article, we implemented "set attributes include different types of members". However, if you want to use the Properties window to edit the items attributes of tbtoolbar, you will find that the Set property editor cannot add members of different types. You can only add original set members. Can it be entered manually only in the aspx program code? Of course, this manual operation is not required. You only need to change the set property editor to meet our needs. This article will introduce how to modify the set property editor.

Download program code: ASP. NET Server Control-day18.rar

1. Custom set property Editor

Let's take a look at the editorattribute applied to the tbtoolbar. Items attribute. It uses the collectioneditor category as the Attribute Editor, so we want to inherit the collectioneditor category and change it to a custom attribute editor.

< _
Editor(GetType(CollectionEditor), GetType(UITypeEditor)) _
> _
Public ReadOnly Property Items() As TBToolbarItemCollection

 

 

 

Add a tbtoolbaritemcollectioneditor class that inherits collectioneditor and add a constructor. This category belongs to the bee. webcontrols. Design namespace. We usually classify the categories used in the design phase into special namespaces for ease of management and use.

Namespace WebControls.Design
    Public Class TBToolbarItemCollectionEditor
        Inherits CollectionEditor
 
        ''' <summary>
'''Constructor.
        ''' </summary>
''' <Param name = "type"> type. </Param>
        Public Sub New(ByVal Type As Type)
            MyBase.New(Type)
        End Sub
 
    End Class
End Namespace

 

 

We can first modify the editorattribute of the items attribute to see if our custom tbtoolbaritemcollectioneditor works properly. However, this Attribute Editor is no different from the original one, because we just inherited it and did not make any changes. Next, we will begin to modify this Attribute Editor.

< _
Editor(GetType(TBToolbarItemCollectionEditor), GetType(UITypeEditor)) _
> _
Public ReadOnly Property Items() As TBToolbarItemCollection

 

2. Add a set Member of Different Types

Now we need to modify the set Attribute Editor so that it can join different types of set members. Override the canselectmultipleinstances method of collectioneditor to return true. This method sets whether collectioneditor allows multiple types of set members.

        Protected Overrides Function CanSelectMultipleInstances() As Boolean
            Return True
        End Function

 

Then override the createnewitemtypes method. This method obtains the data types that can be contained in the Set Editor and returns the data types that can be contained in the set as arrays.

        ''' <summary>
''' Gets the information types that can be included in this set of collectors.
        ''' </summary>
''' <Returns> This set contains the item type columns. </Returns>
        Protected Overrides Function CreateNewItemTypes() As System.Type()
            Dim ItemTypes(2) As System.Type
            ItemTypes(0) = GetType(TBToolbarButton)
            ItemTypes(1) = GetType(TBToolbarTextbox)
            ItemTypes(2) = GetType(TBToolbarLabel)
            Return ItemTypes
        End Function

 

 

Rebuild the control component and use the items set property editor to find that the drop-down list of the Add button shows the three types of set members we have defined, so you can join different types of members.

 

3. Set the display text of the configuration item

In the member list project, the type of the member including the namespace is displayed by default. If we want to change it to a more recognizable display text, such as tbtoolbarbutton (Key = add) the "button-Add" is displayed. You can override the getdisplaytext method to set the display text of the configuration item.

        ''' <summary>
''' Retrieves the text for the specified list.
        ''' </summary>
        Protected Overrides Function GetDisplayText(ByVal value As Object) As String
            If TypeOf value Is TBToolbarButton Then
Return string. Format ("by bytes-{0}", ctype (value, tbtoolbarbutton). Key)
            ElseIf TypeOf value Is TBToolbarTextbox Then
Return "text box"
            ElseIf TypeOf value Is TBToolbarLabel Then
Return string. Format ("standard-{0}", ctype (value, tbtoolbarlabel). Text)
            Else
                Return value.GetType.Name
            End If
        End Function

 

 

 

Iv. attribute description of the property window of the Set Editor

Generally, attribute descriptions are displayed in the Properties window. You can set the attribute descriptions in the attribute window of the property editor. If you want to display its property description, You can override the createcollectionform method to obtain the set property to edit the form, and then set propertygrid. helpvisible = true on the form.

        ''' <summary>
''' Creates a list of two sets of two-dimensional schedulers.
        ''' </summary>
        Protected Overrides Function CreateCollectionForm() As System.ComponentModel.Design.CollectionEditor.CollectionForm
            Dim oForm As CollectionEditor.CollectionForm
            Dim oType As Type
            Dim oFieldInfo As FieldInfo
            Dim oPropertyGrid As System.Windows.Forms.PropertyGrid
 
            oForm = MyBase.CreateCollectionForm()
            oType = oForm.GetType()
            oFieldInfo = oType.GetField("propertyBrowser", BindingFlags.NonPublic Or BindingFlags.Instance)
            If oFieldInfo IsNot Nothing Then
'Retrieve the alert policy window to control the alert policy
                oPropertyGrid = CType(oFieldInfo.GetValue(oForm), System.Windows.Forms.PropertyGrid)
'Set the attention window to control the [description] region of the attention.
                oPropertyGrid.HelpVisible = True
            End If
            Return oForm
        End Function

 

 

 

 

 

Note: This article is also published in "the first it state help tie Ren Competition". If you think this article is helpful to you, remember to repeat it to improve your popularity ^
Http://ithelp.ithome.com.tw/question/10012636

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.