[ASP. NET control implement day21] implement control smart volume label

Source: Internet
Author: User

The control usually displays common properties or functions in the smart volume label, providing users with easier and faster settings, such as the intelligent gridview. To create a smart volume label for a control, you need to implement the actionlist of the control to be added to the project to be displayed in the smart volume label. This article takes the tdateedit control as an example, further describe the implementation method of the smart volume label of the control.

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

 

I,TdateeditControl Introduction

The tdateedit control is a date control implemented by the author in a blog, as shown in. It is a control based on the coolest DHTML calendar date selector of JavaScript. I have included the code of the tdateedit control into the bee. Web. dll component. For more information about the tdateedit control, see the following articles in my blog. This article will take the tdateedit control as an example and only further describe the part that implements smart tags.

Date control implementation teaching (1)-combined with JavaScript
Real-time teaching of date controls (2)-PostBack and events
Tbdateedit date control-version 1.0.0.0 (Open Source)

 

2. Add controls to smart tagging

The control is added to the designer of the smart volume label to implement the control. We inherit the name of controldesigner as tbdateeditdesigner and overwrite the actionlists attribute. This attribute is returned to the project list set contained in the smart volume label. In the actionlists attribute, the actionlists attribute of the parent category is added first, and then the custom actionlist category is added, so that the project list of the smart volume label in the original parent category can be retained.

    ''' <summary>
'''Tbdateedit controls the design mode line of the consumer.
    ''' </summary>
    Public Class TBDateEditDesigner
        Inherits System.Web.UI.Design.ControlDesigner
 
        ''' <summary>
''' Gets a set of action checklists for the control design tool.
        ''' </summary>
        Public Overrides ReadOnly Property ActionLists() As DesignerActionListCollection
            Get
                Dim oActionLists As New DesignerActionListCollection()
                oActionLists.AddRange(MyBase.ActionLists)
                oActionLists.Add(New TBDateEditActionList(Me))
                Return oActionLists
            End Get
        End Property
 
    End Class

 

 

 

The custom actionlist is the tbdateeditactionlist category, as shown in the list of items presented by the smart volume label. Next, we will describe the content of the tbdateeditactionlist category.

 

3. Set a project list for customizing the smart marking panel

The designeractionlist category defines the Base category of the project list used to create the smart volume panel. Therefore, we first inherit the designeractionlist and name it tbdateeditactionlist.

    ''' <summary>
'''Define tbdateedit to control the consumer list set of the consumer Smart Tag panel.
    ''' </summary>
    Public Class TBDateEditActionList
        Inherits DesignerActionList
 
        ''' <summary>
'''Constructor.
        ''' </summary>
        Public Sub New(ByVal owner As ControlDesigner)
            MyBase.New(owner.Component)
        End Sub
 
    End Class

 

 

 

Next, override the getsortedactionitems method. It will return the designeractionitemcollection type, which will return the project list set to be displayed on the Smart volume panel, therefore, we need to add the project list to be presented in the designeractionitemcollection.

        ''' <summary>
'''Items are displayed in the list of items on the Smart Tag panel.
        ''' </summary>
        Public Overrides Function GetSortedActionItems() As System.ComponentModel.Design.DesignerActionItemCollection
            Dim oItems As New DesignerActionItemCollection()
 
'The Project List added here to the Smart Tag panel
 
            Return oItems
        End Function

Step1.Add a static title project to the smart tagging panel

First, we will introduce the designeractionheaderitem category, which is used to set static title items. For example, we add "behavior" and "appearance" Two title items to the Smart tag of tdateedit, the category parameter constructed by the designeractionheaderitem function is the group name. We can classify related projects into the same group.

Dim oItems As New DesignerActionItemCollection()
 
Oitems. Add (New designeractionheaderitem ("row", "behavior "))
Oitems. Add (New designeractionheaderitem ("", "appearance "))

 

Step2.Add a property project to the smart volume label panel

The designeractionpropertyitem category is used to set the attribute item on the Smart volume scale. The first parameter (membername) of the designeractionpropertyitem constructor is the attribute name. This attribute refers to the attribute in the tbdateeditactionlist category, therefore, you must add a corresponding attribute in tbdateeditactionlist.

For example, if you add the autopostback attribute item to the smart volume label, you must have a corresponding autopostback attribute in the tbdateeditactionlist category.

            oItems.Add(New DesignerActionPropertyItem("AutoPostBack", _
"Autopostback", "behavior", "Whether to trigger a PostBack action. "))

 

 

 

The attributes of tbdateeditactionlist. autopostback are as follows. Me. component refers to the current tdateedit control and uses the getpropertyvalue and setpropertyvalue methods to access the specified attributes of the control.

        ''' <summary>
''' Indicates whether to initiate a PostBack action.
        ''' </summary>
        Public Property AutoPostBack() As Boolean
            Get
                Return CType(GetPropertyValue(Me.Component, "AutoPostBack"), Boolean)
            End Get
            Set(ByVal value As Boolean)
                SetPropertyValue(Me.Component, "AutoPostBack", value)
            End Set
        End Property
 
    ''' <summary>
''' Sets the adequacy value of an object.
    ''' </summary>
''' <Param name = "component"> the property value is the object to be set. </Param>
''' <Param name = "propertyname"> the property name is anonymous. </Param>
''' <Param name = "value"> new value. </Param>
    Public Shared Sub SetPropertyValue(ByVal Component As Object, ByVal PropertyName As String, ByVal Value As Object)
        Dim Prop As PropertyDescriptor = TypeDescriptor.GetProperties(Component).Item(PropertyName)
        Prop.SetValue(Component, Value)
    End Sub
 
    ''' <summary>
''' Gets the adequacy value of the object.
    ''' </summary>
''' <Param name = "component"> indicates an object that has the property to be destroyed. </Param>
''' <Param name = "propertyname"> the property name is anonymous. </Param>
    Public Shared Function GetPropertyValue(ByVal Component As Object, ByVal PropertyName As String) As Object
        Dim Prop As PropertyDescriptor = TypeDescriptor.GetProperties(Component).Item(PropertyName)
        Return Prop.GetValue(Component)
    End Function

 

 

Step3.Add a method project to the smart volume label panel

The designeractionmethoditem category is used to set the method item on the Smart volume scale. The second parameter (membername) of the designeractionpropertyitem construction function is the method name. This method refers to the method in the tbdateeditactionlist category, therefore, you must add a corresponding method in tbdateeditactionlist.

For example, if the about method item is added to the smart volume label, a corresponding about method is required for the tbdateeditactionlist category.

            oItems.Add(New DesignerActionMethodItem(Me, "About", _
"Related to tdateedit control rule", "about ",_
"Tdateedit controls the volume. ", True ))

 

 

 

The about method of tbdateeditactionlist only displays a message window. Generally, you can add any action to be processed in the design phase. For example, fields in the gridview are automatically generated, controls are added to the formview, and automatic formatting is performed here.

        Public Sub About()
Msgbox ("tdateedit is the control component that combines the coolest DHTML calendar date selector practices ")
        End Sub

 

 

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/10012896
Http://ithelp.ithome.com.tw/question/10012897

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.