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

Discussion in 'ASP .Net Building Controls' started by George, Jan 8, 2004.

  1. George

    George Guest

    Hi,

    I have implemented the code similar to the one on the link:
    http://www.microsoft.com/japan/msdn...ystemwebuidesigncontroldesignerclasstopic.asp

    The problem is that the caption in the properties pane doesn't change after
    click (although the design of the control itself and the context menu is
    changed properly). Is it necessary to call some other method to update
    properties pane?

    Thanks a lot for any info.

    Jiri Brazda
     
    George, Jan 8, 2004
    #1
    1. Advertising

  2. 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.
     
    Jeffrey Tan[MSFT], Jan 9, 2004
    #2
    1. Advertising

  3. 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.
     
    Jeffrey Tan[MSFT], Jan 12, 2004
    #3
  4. 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.
     
    Jeffrey Tan[MSFT], Jan 14, 2004
    #4
  5. 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.
     
    Jeffrey Tan[MSFT], Jan 19, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick.O.Ige
    Replies:
    0
    Views:
    779
    Patrick.O.Ige
    Aug 31, 2006
  2. Adam M
    Replies:
    1
    Views:
    420
    Adam M
    Jan 23, 2008
  3. Harlan Messinger
    Replies:
    0
    Views:
    382
    Harlan Messinger
    Feb 18, 2008
  4. Mateus Padovani Velloso

    Web Custom Control, design-time property doesn't change attribute

    Mateus Padovani Velloso, Jan 11, 2005, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    252
    Mateus Padovani Velloso
    Feb 7, 2005
  5. N Kumar

    Setting web custom control properties at design time

    N Kumar, Feb 21, 2006, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    173
    Teemu Keiski
    Feb 23, 2006
Loading...

Share This Page