. NET component Programming (7) Component designeraction (smart tag)

Source: Internet
Author: User

The introduction to DesignerActionList and DesignerAction on MSDN is: The DesignerAction feature allows components and controls to display case-sensitive information and commands. The DesignerAction feature can be treated as a substitute for a designer verb because designeractionitem can appear in the smart tag panel or in a shortcut menu associated with a component or control. For developers who want to add smart tag support to custom components and controls, the DesignerActionList class represents the primary interaction point. DesignerActionList is a base class that component developers can derive from to populate the smart tag panel. The smart tag panel represents a smart tag as a menu-like user interface (UI).

Designeractionitem is an item on the smart panel, we want to add an item to the smart panel, just instantiate a designeractionitem, There is a method in the DesignerActionList class that can be override Getsortedactionitems () return type is designeractionitemcollection, which is actually returning the collection of items on the smart panel. We simply add the Designeractionitem instance to the return value of Getsortedactionitems ().

In. NET, Designeractionmethoditem, Designeractionpropertyitem, Designeractiontextitem, Designeractionheaderitem inherits from Designeractionitem, most of whose members are the same, Designeractionmethoditem generates a method item primarily on the smart panel. Clicking on this item will perform the appropriate method; Designeractionpropertyitem the component attribute on the smart panel, and the user can set and modify the component properties on the function panel. Designeractiontextitem is a text item that is generated on the smart panel, and Designeractionheaderitem is inherited from Designeractiontextitem, but it has more than one grouping function.

The code demonstrates the following:

Using System.Collections.Generic;


using System;


using System.Drawing;


using System.Collections;


using System.ComponentModel;


using System.ComponentModel.Design;


using System.Text;


using System.Reflection;


using System.Windows.Forms;





namespace ClassLibrary1


{


[Designer (typeof (Customerdesigner), typeof (IDesigner))]


public class Customer:component


    {


private string _id;


private Sex _sex;


private String _address;





public string Id


        {


get {return _id;}


set {_id = value;}


        }





Public Sex Sex


        {


get {return _sex;}


set {_sex = value;}


        }





public string Address


        {


get {return _address;}


set {_address = value;}


        }


    }





public enum Sex


    {


male = 0,


female = 1


    }





public class Customerdesigner:componentdesigner


    {


private DesignerActionListCollection actionlists;





//Only get, no set.


public override DesignerActionListCollection actionlists


        {


Get


            {


if (null = = actionlists)


                {


actionlists = new DesignerActionListCollection ();


Actionlists.add (


new Customeractionlist (this.component));


                }


return actionlists;


            }


        }





private void OnClick2 (object sender, EventArgs e)


        {


MessageBox.Show ("Click2.");


        }





//Added a predicate (appears in the right-click menu).


//If designeractionlist is overridden, this verb is not added to the smart tag.


public Customerdesigner ()


        {


DesignerVerb verb2 = new DesignerVerb ("Click2", New EventHandler (OnClick2));


this. Verbs.add (VERB2);


        }


    }





DesignerActionList: List of items on the smart tag panel


public class Customeractionlist:designeractionlist


    {


private customer customer;





public Customeractionlist (IComponent component): Base (component)


        {


This.customer = component as Customer;


        }





        /**//*


typedescriptor--through the type to obtain component attribute, property, Event.


         */


public string Id//NOTE 1


        {


Get


{return customer. Id; }


Set


{typedescriptor.getproperties (typeof (Customer)) ["Id"]


                . SetValue (Customer, value);


            }


        }





Public Sex Sex


        {


Get


{return customer. Sex; }


Set


{typedescriptor.getproperties (typeof (Customer)) ["Sex"]


                . SetValue (Customer, value); }


        }





public void OnClick1 ()


        {


MessageBox.Show ("Click1.");


        }





public override Designeractionitemcollection Getsortedactionitems ()


        {


designeractionitemcollection items = new Designeractionitemcollection ();





//HeaderItem


//Create a taxonomy of items on the smart panel.


Designeractionheaderitem hInfo = new Designeractionheaderitem ("Customer ' s Info", "info");


items. ADD (HInfo);





Designeractionheaderitem haction = new Designeractionheaderitem ("Customer ' s Action", "action");


items. ADD (haction);





Designeractionheaderitem hdescription = new Designeractionheaderitem ("Description");


items. ADD (hdescription);





//PropertyItem


//Designeractionpropertyitem ("Id"-the property of note 1 position


//, "Id"--the name displayed on the smart panel


//, "Info"--categories on the smart panel


//, "Customer ' s ID")--Supplemental explanatory text


items. ADD (New Designeractionpropertyitem ("id", "id", "Info", "Customer ' s ID"));


items. ADD (New Designeractionpropertyitem ("Sex", "Sex", "Info", "Customer ' s Sex"));








Add a Methoditem.


//This methoditem adds an item to the component right-click menu by default.


items. ADD (This, "OnClick1", "Click1", "Action", True) (Designeractionmethoditem);





//Add a textitem.


items. ADD (New Designeractiontextitem ("http://mapserver.cnblogs.com", "Description"));





return items;


        }


    }


}

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.