Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I have implemented a custom Control (Graph) for my own custom Designer. It works well so far.
Now I would like to add Smarttags to this control to get access to the most important properties.

Therefore I implemented a ControlDesigner whicht implements a DesignerActionList and so on (like in this article here: Customizing User Controls with Smart Tag Feature[^]

Also I added the desiner attribute to my control class.


But nothing happens. There is no smarttag in designmode and when debugging the design time part, the smarttag/designer code is not getting accessed.


What did I miss/forget??



Here is the code snipped:

C#
[Designer(typeof(TGraphDesigner))] [ToolboxBitmap(typeof(TGraph))] public class TGraph : TDiagramControl // UserControl { 
public TGraph() : base() { //Init.... } 

protected override void OnPaint(PaintEventArgs e) 
{ ... } 
} 


[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
public class TGraphDesigner : System.Windows.Forms.Design.ControlDesigner 
{ 
private DesignerActionListCollection actionLists; 

public override DesignerActionListCollection ActionLists 
{ 
get 
{ 
if (null == actionLists) 
{ 
actionLists = new DesignerActionListCollection(); 
actionLists.Add(new TGraphActionList(this.Component)); 
} 
return actionLists; 
} 
} 
} 

public class TGraphActionList : DesignerActionList 
{ 
private TGraph customControl; 
private DesignerActionUIService designerActionUISvc = null; 

public TGraphActionList(IComponent component) : base(component) 
{ 
this.customControl = component as TGraph; 
this.designerActionUISvc = GetService(typeof(DesignerActionUIService)) as DesignerActionUIService; 
} 

private PropertyDescriptor GetPropertyByName(String propName) 
{ 
PropertyDescriptor prop; 
prop = TypeDescriptor.GetProperties(customControl)[propName];
if (null == prop) 
throw new ArgumentException("Matching ColorLabel property not found!", propName); 
else 
return prop; 
} 

public Color BackColor 
{ 
get { return customControl.BackColor; } 
set { GetPropertyByName("BackColor").SetValue(customControl, value); } 
} 

public Color ForeColor 
{ 
get { return customControl.ForeColor; } 
set { GetPropertyByName("ForeColor").SetValue(customControl, value); } 
} 

public override DesignerActionItemCollection GetSortedActionItems() 
{ 
DesignerActionItemCollection items = new DesignerActionItemCollection(); 
items.Add(new DesignerActionHeaderItem("Appearance")); items.Add(new DesignerActionPropertyItem("BackColor", "Back Color", "Appearance", "Selects the background color.")); 
items.Add(new DesignerActionPropertyItem("ForeColor", "Fore Color", "Appearance", "Selects the foreground color.")); return items; 
} 
}


Thanks a lot !!!
Posted
Updated 5-Feb-12 21:18pm
v2

1 solution

Hi,

If you followed mentioned article all should work.
Did you put DesignerAttribute on your control. Class (control) must be decorated with atribute.
C#
[Designer(typeof(YourControlDesigner))]
public class YourControl : UserControl

That way visual studio knows what ControlDesigner will be used...
 
Share this answer
 
Comments
akamper 3-Feb-12 15:12pm    
Thanks for your hint, but yes I did.

I will post the code on monday (not near the pc over the weekend).
akamper 6-Feb-12 3:11am    
So here the code snippet:

<pre lang="c#">
[Designer(typeof(TGraphDesigner))]
[ToolboxBitmap(typeof(TGraph))]
public class TGraph : TDiagramControl // UserControl
{
public TGraph()
: base()
{
//Init....
}

protected override void OnPaint(PaintEventArgs e)
{
...
}
}



[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
public class TGraphDesigner : System.Windows.Forms.Design.ControlDesigner
{
private DesignerActionListCollection actionLists;

// Use pull model to populate smart tag menu.
public override DesignerActionListCollection ActionLists
{
get
{
if (null == actionLists)
{
actionLists = new DesignerActionListCollection();
actionLists.Add(new TGraphActionList(this.Component));
}
return actionLists;
}
}
}
public class TGraphActionList : DesignerActionList
{
private TGraph customControl;

private DesignerActionUIService designerActionUISvc = null;

//The constructor associates the control with the smart tag list.
public TGraphActionList(IComponent component)
: base(component)
{
this.customControl = component as TGraph;

// Cache a reference to DesignerActionUIService, so the DesigneractionList can be refreshed.
this.designerActionUISvc = GetService(typeof(DesignerActionUIService)) as DesignerActionUIService;
}

// Helper method to retrieve control properties. Use of GetProperties enables undo and menu updates to work properly.
private PropertyDescriptor GetPropertyByName(String propName)
{
PropertyDescriptor prop;
prop = TypeDescriptor.GetProperties(customControl)[propName];
if (null == prop)
throw new ArgumentException("Matching ColorLabel property not found!", propName);
else
return prop;
}

// Properties that are targets of DesignerActionPropertyItem entries.
public Color BackColor
{
get
{
return customControl.BackColor;
}
set
{
GetPropertyByName("BackColor").SetValue(customControl, value);
}
}

public Color ForeColor
{
get
{
return customControl.ForeColor;
}
set
{
GetPropertyByName("ForeColor").SetValue(customControl, value);
}
}


//Implementation of this abstract method creates smart tag items, associates their targets, and collects into list.
public override DesignerActionItemCollection GetSortedActionItems()
{
DesignerActionItemCollection items = new DesignerActionItemCollection();

//Define static section header entries.
items.Add(new DesignerActionHeaderItem("Appearance"));

items.Add(new DesignerActionPropertyItem("BackColor",
"Back Color", "Appearance",
"Selects the background color."));
items.Add(new DesignerActionPropertyItem("ForeColor",
"Fore Color", "Appearance",
"Selects the foreground color."));
return items;
}
}










</pre>





Nothing happens. So I cannot access designer code while debugging design time...

I hope you can help me and give me a hint, what I missed.

thanks
Martin Arapovic 6-Feb-12 10:28am    
hi, I just try solution this solution http://www.codeproject.com/Articles/37103/Customizing-User-Controls-with-Smart-Tag-Feature and it is working, so compare it with you code and see what you are missing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900