Create your own Designer or Introduction To Custom Designers - Part 3: SmartTags and Source Code.
As I promised I will supply the source code for the Designer and I will explain about SmartTags, SmartTags enable us easier access to our control an extended to UI.
So SmartTags enable us to access designated operation to our control.
How to create SmartTas:
Step 1:
In my previous session I have demonstrated how to create a Custom Designer, now all you have to do to add SmartTags to your control is to override the ActionLists property of your desginer.
private DesignerActionList m_DesignerActionList;
private DesignerActionListCollection m_ActionLists;
public override DesignerActionListCollection ActionLists
{
get
{
if(m_ActionLists == null)
{
m_ActionLists = new DesignerActionListCollection();
m_DesignerActionList = new MyDesignerActionList(this.Control);
m_ActionLists.Add(m_DesignerActionList);
}
return m_ActionLists;
}
}
As you may have notice I have created my own implementation of the DesignerActionList class, the new implementation contains the definition of SmartTags abilities exposed by my new DesignerActionList class.
Step 2: Add abilities to your DesignerActionList
To add new SmartTags all you have to do is to override the GetSortedActionItems method and add the Method to be Invoked when the SmartTag is invoked. By adding DesignerActionItemCollection a DesignerActionMethodItem we will Invoke a method.
public override DesignerActionItemCollection GetSortedActionItems()
{
DesignerActionItemCollection items = new DesignerActionItemCollection();
items.Add(new DesignerActionMethodItem(this,
"ImageLocation", "ImageLocation",true));
return items;
}
Now when we will design our control we will be able to use SmartTags.
I have Included source code for our designer.
SourceCode
That's it.
*njoy!