Live Chat Icon For mobile
Live Chat Icon

How do I control the state of my custom verb in my designer?

Platform: WinForms| Category: Custom Designers

You have to store a reference to the DesignerVerb instance you create to represent the custom verb. You can then update the state of the verb through this reference. Here is an example:


public class MyControlDesigner : ParentControlDesigner
{
    private DesignerVerb removeVerb;
    private DesignerVerbCollection verbs;
    ...

    public override /*ParentControlDesigner*/ void Initialize(IComponent component)
    {
        //... 
        // Update your designer verb whenever ComponentChanged event occurs.
        iComponentChangeService = (IComponentChangeService) this.GetService(typeof(IComponentChangeService));
        if (iComponentChangeService != null)
            iComponentChangeService.ComponentChanged += new ComponentChangedEventHandler(this.ComponentChanged);

    }

    protected override void Dispose(bool disposing)
    {
        ...
        if (iComponentChangeService != null)
            iComponentChangeService.ComponentChanged -= new ComponentChangedEventHandler(this.ComponentChanged);
    }

    public override DesignerVerbCollection Verbs
    {
        get
        {
            if (this.verbs == null)
            {
                this.removeVerb = new DesignerVerb('Remove Tab', new EventHandler(this.OnRemove));
                this.verbs = new DesignerVerbCollection();
                this.verbs.Add(this.removeVerb);
            }
            this.removeVerb.Enabled = (this.Control.Controls.Count > 0);
            return this.verbs;
        }
    }

    private void UpdateVerbStatus()
    {
        if (this.removeVerb != null) this.removeVerb.Enabled = (this.Control.Controls.Count > 0);
    }

    private void CheckVerbStatus(object sender, ComponentChangedEventArgs e)
    {
        this.UpdateVerbStatus();
    }
}

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.