Hi George,
Sorry for letting you wait for so long time.
I have done a lot of research on this issue. Actually, the sample in MSDN
of ControlDesigner class is somewhat incorrect.
Because when the font size of the control is changed, it's not changing
anything on the control itself so at runtime. There is no way for the
property browser to know that something has changed on the control.
================================
To workaround this issue, you have to make the LargeText a property of your
control, so when you change the LargeText, property browser is refreshed.
Sample code like this:
public class TextSizeWebControlDesigner :
System.Web.UI.Design.ControlDesigner
{
public TextSizeWebControlDesigner() : base()
{
}
public override void Initialize(IComponent component)
{
base.Initialize (component);
((TextControl)this.Component).LargeText=false;
}
DesignerVerb _reduce, _enlarge;
public override System.ComponentModel.Design.DesignerVerbCollection Verbs
{
get
{
if (base.Verbs.Count != 0)
{
return base.Verbs;
}
DesignerVerbCollection dvc = base.Verbs; //new DesignerVerbCollection();
_reduce = new DesignerVerb("Reduce text size", new
EventHandler(this.reduceTextSize));
_enlarge = new DesignerVerb("Enlarge text size", new
EventHandler(this.enlargeTextSize));
bool largeText = ((TextControl)this.Component).LargeText;
_reduce.Enabled = largeText;
_enlarge.Enabled = !largeText;
dvc.Add(_enlarge);
dvc.Add(_reduce);
return dvc;
}
}
// Returns the html to use to represent the control at design time.
public override string GetDesignTimeHtml()
{
string html = base.GetDesignTimeHtml();
if( ((TextControl)this.Component).LargeText )
return "<H1>"+html+"</H1>";
else
return "<H3>"+html+"</H3>";
}
private void reduceTextSize(object sender, EventArgs e)
{
ChangeTextSize(false);
}
private void enlargeTextSize(object sender, EventArgs e)
{
ChangeTextSize(true);
}
private void ChangeTextSize(bool enlarge)
{
PropertyDescriptor largeTextProp =
TypeDescriptor.GetProperties(Component)["LargeText"];
_reduce.Enabled = enlarge;
_enlarge.Enabled = !enlarge;
largeTextProp.SetValue(this.Component, enlarge);
this.IsDirty = true;
this.UpdateDesignTimeHtml();
}
}
[DesignerAttribute(typeof(TextSizeWebControlDesigner), typeof(IDesigner))]
public class TextControl : System.Web.UI.WebControls.WebControl
{
private string text;
private bool b_LargeText;
[Bindable(true),Category("Appearance"),DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
public bool LargeText
{
get
{
return b_LargeText;
}
set
{
b_LargeText=value;
}
}
public TextControl()
{
text = "Test phrase";
}
protected override void Render(HtmlTextWriter output)
{
output.Write(Text);
}
}
I add both verbs and every time, we only enable one verb.
Please apply my suggestion above and let me know if it helps resolve your
problem.
===============================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.