Properties pane of custom control doesn't change in design time

J

Jeffrey Tan[MSFT]

Hi George,

Thanks for posting in this group.
What is your properties pane? Is it the Property Grid of the IDE?
If it is, what is the caption of your Property Grid?
Actually, I did not fully understand your problem, I hope to receive more
detailed description form you.

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.
 
J

Jeffrey Tan[MSFT]

Hi George,

Thanks for your feedback.
I understand your problem. I found that it was because that the
propertygrid did not refresh.
If you de-select your control and re-select your control again, you will
find that the command on the propertygrid of the IDE does change its text.
I still did not find a workaround for this issue.
I will do more research on it, and will reply to you ASAP.
Thanks for your understanding.

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.
 
J

Jeffrey Tan[MSFT]

Hi George,

I have contacted product group on it and this may need some time. Thanks
for your patience.

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.
 
J

Jeffrey Tan[MSFT]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top