asp.net 服务器控件 定义控件的Designer类,但不知点样子进行调试。
代码很简单,在最后会给出。但是问题在于好象没有办法对 TextSizeWebControlDesigner 类进行调试和跟踪。
因为TextSizeWebControlDesigner会表现在设计时的相式设了断点也没办法。
请教大家有没有调试这个类的方法。
// This control designer offers designer verb menu commands
// that can alter the design time html provided for the
// System.Web.UI.Control this designer supports.
public class TextSizeWebControlDesigner : System.Web.UI.Design.ControlDesigner
{
// Whether to display the html of the associated
// control using a large heading text size.
private bool LargeText;
public TextSizeWebControlDesigner()
: base()
{
LargeText = false;
}
// Provides a menu command to toggle the text size.
public override System.ComponentModel.Design.DesignerVerbCollection Verbs
{
get
{
DesignerVerbCollection dvc = new DesignerVerbCollection();
if (LargeText)
dvc.Add(new DesignerVerb("Reduce text size", new EventHandler(this.toggleTextSize)));
else
dvc.Add(new DesignerVerb("Enlarge text size", new EventHandler(this.toggleTextSize)));
return dvc;
}
}
// Returns the html to use to represent the control at design time.
public override string GetDesignTimeHtml()
{
Form1 form = new Form1();
form.ShowDialog();
string html = base.GetDesignTimeHtml();
if (LargeText)
return "<H1>" + html + "</H1>";
else
return "<H3>" + html + "</H3>";
}
// Event handler to toggle whether the html receives a large or
// small size heading markup tag.
private void toggleTextSize(object sender, EventArgs e)
{
if (LargeText)
LargeText = false;
else
LargeText = true;
this.Tag.SetDirty(true);
this.UpdateDesignTimeHtml();
}
}
// Simple text web control renders a text string.
// This control is associated with the TextSizeWebControlDesigner.
[DesignerAttribute(typeof(TextSizeWebControlDesigner), typeof(IDesigner))]
public class TextControl : System.Web.UI.WebControls.WebControl
{
private string text;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
public TextControl()
{
text = "Test phrase";
}
protected override void Render(HtmlTextWriter output)
{
output.Write(Text);
}
}
补充:.NET技术 , ASP.NET