Undo, Cut, Copy, Paste, Delete, Select All; Check to see if enabled or disabled

I have the "standard" edit menu along with the "standard" tool strip. What I am wondering is how to enable and disable the buttons (listed below) depending on if you can actually preform those action. So for example I can not paste something unless i have something in my clipboard along with being in a text box. So how would I enable that or disable those button automatically when that before true or false Like they would in MS office.

Menu Strip: Undo, Cut, Copy, Paste, Delete, Select All
Tool Strip: Undo, Cut, Copy, Paste


Answer this question

Undo, Cut, Copy, Paste, Delete, Select All; Check to see if enabled or disabled

  • MueMeister

    I wouldn't worry about what the clipboard contains. The user can switch to another application and copy something else to the clipboard anyway so unless you want to check every time your app is actiavted as well then just test the clipboard when they try to paste. I'd suggest that you read the help/MSDN topic for the TextBoxBase.Paste method as the code example might be helpful. As for the type of the current control, just create a single Enter event handler for every control and test the type of the sender:

    myCopyMenuItem.Enabled = TypeOf sender Is TextBoxBase


  • G. Rahul

    I have the same question that Grant has. I need a way to enable/disable all the clipboard commands. Ideally, this mechanism would be through an Interface so I don't have to know about specific UI controls like TextBox.

    This is pretty important, and I'm hoping it should be fairly easy for the WPF team to add.

    E.g., a fictional IClipboardTarget (you can come up with a better name) interface could have these methods:

    • CanCopy
    • CanCut
    • CanPaste
    • Copy
    • Cut
    • Paste

    Editable controls like TextBox and any custom control I write could implement IClipboardTarget. TextBox knows about its own internal state and can answer the questions for me. For example, CanCut would check (a) is there a selection (b) is this control readonly Is it enabled

    It doesn't make sense for every client of TextBox to have to think of all the things they need to check before knowing that Cut or Copy or Paste can be enabled.



  • Undo, Cut, Copy, Paste, Delete, Select All; Check to see if enabled or disabled