Fully explored in the Web Control ASP.NET 2.0 technologies to improve sensitivity label articles (3)
When you first use the Visual Studio 2005 Windows Forms control or ASP.NET Web controls, you will first note that a number of controls in the upper right corner appears an arrow-shaped gadget (see Figure 2 example) . Click on the arrow will pop up a small window that contains the control of some properties, there are one or two links. Microsoft designed these sensitive labels yes Weiliaoxianshi you Xuyao operation of Yixiezhuxing, the ultimate aim is to put the Kong Jian Shang in a page or form correctly Gongzuo; Bingju you will note, Ta Men than an ordinary Kuaijie menu Gengwei fine . In this section, we discuss the content applies to both Windows Forms controls also apply to ASP.NET server control.
Figure 2: EmailContact control of sensitive labels
In order to build your own sensitive labels, you need to use a control designer class. In fact, you are also a number of other issues will also use this class. However, I discuss the design details of class, I would like to create a ActionList class - this class will define the sensitive Biaoqian I included elements.
A ActionList class inherits from System.ComponentModel.Design namespace DesignerActionList class. However, detailed discussion of this class, let me first explain the label present in the sensitive elements of four types: category header, property mapping, action link and information item. Figure 2 shows the sensitivity label me build this goal. I mean you can see from these four types of elements? I put this sensitive labels fall into three categories under the heading: "Appearance & Behavior", "Support" and "Information". One, "Appearance & Behavior" category includes two attributes: Mail Server and the Pre-defined Display. These are actually EmailContact control their own property. "Support" category contains two activation behavior of certain types of a link, while the "Information" category is only used to display information. Now, with these four types of elements, I will set out to create my ActionList class.
I will create a class called EmailContactActionList, and to be derived from the DesignerActionList in. (You can see this source list, a full class). I will create a constructor - it receives a EmailContact instance as a parameter and to extend its scope to a class-level variable called ctlEmailContact. Later, when I add the code to the designer class, you will see the use of this constructor. Now, I have created a class-level object that contains my control are examples of Web design.
Next, I will create a smart label will display the attributes of "property mapping". In Figure 2, you see I've been successful in the sensitive label out of two properties: MailServer and PreDefinedDisplay. These will be mapped to EmailContact called MailServer and PreDefinedDisplay control the properties. ActionList class property mapping will get access to the properties of the control device in return, and in the set access control device to set the properties. However, Microsoft infrastructure design ActionList determined, you can not directly set the control's properties. Instead, you must use reflection to access the control's properties, and then set its value. To facilitate this implementation, I wrote a method called GetControlProperty, it can return a PropertyDescriptor object. This way, developers do not need to repeat the mapping of each property under the reflection code. Below is a property map would look like.
Public Property MailServer () As String
Get
Return ctlEmailContact.MailServer
End Get
Set (ByVal value As String)
GetControlProperty ("MailServer"). _
SetValue (ctlEmailContact, value)
End Set
End Property
Next, I need to establish is that you can see in Figure 2, link: "About EmailContact" and one to my own websites. These links will be implemented in this class I created method. My first method, called ShowAboutBox, it displays a Windows form to be used as a control of my "About" message prompt. The second method is called LaunchWebSite, it performs an System.Diagnostics.Process.Start call to start a browser instance of my site. These two methods only requirement is that: each signature must be a "Sub" (in the C # language, corresponding to a void function), and no arguments.
Note that in this example, sensitive labels show only two attributes and two links, but I have demonstrated by means of technology, you can provide what you need to do more of these objects can be. However, I recommend: Do not use too much sensitive information to override a label. Remember, you only want to put this information to the developer page for immediate use, enabling a more intuitive Web control development.
Now that I have created my attributes and behavior mapping method, then the next, I will create a sensitive labels. Which, DesignerActionList class provides an overloaded function called GetSortedActionItems. After a design class will override this function, and it will return a DesignerActionItemCollection (defined in System.ComponentModel.Design namespace) type of object.
This property is overloaded to achieve some will create a new DesignerActionItemCollection object and use the four different classes (DesignerActionHeaderItem, DesignerActionPropertyItem, DesignerActionMethodItem and DesignerActionTextItem) examples to fill it. Note that these four categories are derived from the abstract DesignerActionItem class. Next, I will discuss with you one by one.
Dim o_Items As DesignerActionItemCollection = _
New DesignerActionItemCollection
This code uses DesignerActionHeaderItem class to create a sensitive label classification head, and in their constructor to receive classification name. I will be directly inserted into an instance of this class I have created the collection.
o_Items.Add (New DesignerActionHeaderItem (_
"Appearance & Behavior"))