本文介绍了如何在自定义控件(DesignMode)中访问/调用SmartTag的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我已经为自己的自定义设计器实现了自定义控件(图形).到目前为止效果很好.
现在,我想向此控件添加Smarttag,以访问最重要的属性.

因此,我实现了一个ControlDesigner,该控件实现了DesignerDesignList等(如本文中的此处所示: [ ^ ]

我也将desiner属性添加到我的控件类.


但是什么也没发生.在设计模式下没有smarttag,并且在调试设计时间部分时,无法访问smarttag/designer代码.


我想念/忘记了什么?



以下是代码片段:

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:

[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 !!!

推荐答案

[Designer(typeof(YourControlDesigner))]
public class YourControl : UserControl


这样,Visual Studio就知道将使用哪种ControlDesigner ...


That way visual studio knows what ControlDesigner will be used...


这篇关于如何在自定义控件(DesignMode)中访问/调用SmartTag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 06:57