I have implemented a custom control but for it working, I must extend the design-time support for the control and create smart tags. I create a custom Designer class derived from ControlDesigner, a DesignerActionList and add the DesignerActionList to the CustomDesigner::ActionLists appropriately but when I switch to the Winforms Designer, I cannot see the smart tags panel. Whatever I try, I cannot succeed. I tried the example in the documentation but the smart tags also don't show up for the custom control ColorLabel.
I am following the exact procedure in the documentation example. So, if you try to reproduce the issue. You can refer to that. Also, I use .Net 6 Winforms Application.
The sample custom control and Designer for it:
[Designer(typeof(ColorLabelDesigner))]
public class ColorLabel : Label
{
private bool colorLockedValue = false;
public bool ColorLocked
{
get
{
return colorLockedValue;
}
set
{
colorLockedValue = value;
}
}
public override Color BackColor
{
get
{
return base.BackColor;
}
set
{
if (ColorLocked)
return;
else
base.BackColor = value;
}
}
public override Color ForeColor
{
get
{
return base.ForeColor;
}
set
{
if (ColorLocked)
return;
else
base.ForeColor = value;
}
}
}
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
public class ColorLabelDesigner :
ControlDesigner
{
private DesignerActionListCollection actionLists;
public override DesignerActionListCollection ActionLists
{
get
{
if (null == actionLists)
{
actionLists = new DesignerActionListCollection();
actionLists.Add(
new ColorLabelActionList(this.Component));
}
return actionLists;
}
}
}
public class ColorLabelActionList :
System.ComponentModel.Design.DesignerActionList
{
private ColorLabel colLabel;
private DesignerActionUIService designerActionUISvc = null;
public ColorLabelActionList(IComponent component) : base(component)
{
this.colLabel = component as ColorLabel;
this.designerActionUISvc =
GetService(typeof(DesignerActionUIService))
as DesignerActionUIService;
}
private PropertyDescriptor GetPropertyByName(String propName)
{
PropertyDescriptor prop;
prop = TypeDescriptor.GetProperties(colLabel)[propName];
if (null == prop)
throw new ArgumentException(
"Matching ColorLabel property not found!",
propName);
else
return prop;
}
public Color BackColor
{
get
{
return colLabel.BackColor;
}
set
{
GetPropertyByName("BackColor").SetValue(colLabel, value);
}
}
public Color ForeColor
{
get
{
return colLabel.ForeColor;
}
set
{
GetPropertyByName("ForeColor").SetValue(colLabel, value);
}
}
public bool LockColors
{
get
{
return colLabel.ColorLocked;
}
set
{
GetPropertyByName("ColorLocked").SetValue(colLabel, value);
this.designerActionUISvc.Refresh(this.Component);
}
}
public String Text
{
get
{
return colLabel.Text;
}
set
{
GetPropertyByName("Text").SetValue(colLabel, value);
}
}
public void InvertColors()
{
Color currentBackColor = colLabel.BackColor;
BackColor = Color.FromArgb(
255 - currentBackColor.R,
255 - currentBackColor.G,
255 - currentBackColor.B);
Color currentForeColor = colLabel.ForeColor;
ForeColor = Color.FromArgb(
255 - currentForeColor.R,
255 - currentForeColor.G,
255 - currentForeColor.B);
}
public override DesignerActionItemCollection GetSortedActionItems()
{
DesignerActionItemCollection items = new DesignerActionItemCollection();
//Define static section header entries.
items.Add(new DesignerActionHeaderItem("Appearance"));
items.Add(new DesignerActionHeaderItem("Information"));
//Boolean property for locking color selections.
items.Add(new DesignerActionPropertyItem("LockColors",
"Lock Colors", "Appearance",
"Locks the color properties."));
if (!LockColors)
{
items.Add(new DesignerActionPropertyItem("BackColor",
"Back Color", "Appearance",
"Selects the background color."));
items.Add(new DesignerActionPropertyItem("ForeColor",
"Fore Color", "Appearance",
"Selects the foreground color."));
items.Add(new DesignerActionMethodItem(this,
"InvertColors", "Invert Colors",
"Appearance",
"Inverts the fore and background colors.",
true));
}
items.Add(new DesignerActionPropertyItem("Text",
"Text String", "Appearance",
"Sets the display text."));
StringBuilder location = new StringBuilder("Location: ");
location.Append(colLabel.Location);
StringBuilder size = new StringBuilder("Size: ");
size.Append(colLabel.Size);
items.Add(new DesignerActionTextItem(location.ToString(),
"Information"));
items.Add(new DesignerActionTextItem(size.ToString(),
"Information"));
return items;
}
}
There should be some configurations that are missing but I have no previous experience on Design-Time Development.
The question is not about How to create the smart tags but How can I add the smart tags for my custom control properly so that it shows up?