Editor for WinForms | ComponentOne
Creating an XHTML Editor in Code / The ToolStripMain class / Enabling and Disabling Commands
In This Topic
    Enabling and Disabling Commands
    In This Topic

    Many of the commands described above may or may not be available depending on whether a document is currently loaded, the selection state, or the clipboard content. If a command is not available, it should be disabled in the tool strip.

    The ToolStripMain class handles this by overriding the UpdateState method as follows:

    To write code in C#

    C#
    Copy Code
    public override void UpdateState()
    {
        Enabled = Editor != null;
        _btnCopy.Enabled = _btnCut.Enabled = Editor.CanCopy;
        _btnPaste.Enabled = Editor.CanPasteAsText; // CanPaste
        _btnUndo.Enabled = Editor.CanUndo();
        _btnRedo.Enabled = Editor.CanRedo();
        _btnSpell.Enabled = _btnShowErrors.Enabled = SpellChecker != null;
    }
    

    The implementation is self-explanatory. The C1Editor provides properties and methods that allow the toolstrip to update itself very easily.