none
How do i use keyboard shortcuts and use cut, copy, paste, and undo?

    Question

  • Can someone show me a couple lines of code to make shortcut keys. Also it would be handy if someone can show me how to write some code to use undo, cut, copy, and paste. Thanks.
    Friday, November 24, 2006 5:36 PM

Answers

  • well the cut/copy/paste is usually in the Control that is TextBox based...

    this.theTextBox.Paste();

    this.theTextBox.Copy(); //you need to set the selectionstart/selectionlength properties so it can copy it from that.

    in regards to shortcut keys - in what sense? The standard Windows shortcut keys for cut/copy/paste still apply even for your app as they are standard Windows shortcut keys. Otherwise to make your own I guess you need to implement the keydown event of the control and check the KeyEventArgs for which key they pressed and perform your action based on that selection.

    private void textbox1_keydown(object sender, KeyEventArgs e)

    {

       if (e.KeyData == Keys.H)

       {

          //user pressed the h key in the textbox1 control

       }

    }

    Friday, November 24, 2006 5:45 PM
    Moderator
  • Keyboard shortcuts are handled directly by the  controls (e.g. pressing Ctrl+V when a TextBox has focus will perform a paste).  In what context do you want to do this?
    Friday, November 24, 2006 7:10 PM
    Moderator
  • just press CTRL+Z or the control's Undo method, should it have one:

    this.theTextBox.Undo();

    Friday, November 24, 2006 9:04 PM
    Moderator

All replies

  • well the cut/copy/paste is usually in the Control that is TextBox based...

    this.theTextBox.Paste();

    this.theTextBox.Copy(); //you need to set the selectionstart/selectionlength properties so it can copy it from that.

    in regards to shortcut keys - in what sense? The standard Windows shortcut keys for cut/copy/paste still apply even for your app as they are standard Windows shortcut keys. Otherwise to make your own I guess you need to implement the keydown event of the control and check the KeyEventArgs for which key they pressed and perform your action based on that selection.

    private void textbox1_keydown(object sender, KeyEventArgs e)

    {

       if (e.KeyData == Keys.H)

       {

          //user pressed the h key in the textbox1 control

       }

    }

    Friday, November 24, 2006 5:45 PM
    Moderator
  • Keyboard shortcuts are handled directly by the  controls (e.g. pressing Ctrl+V when a TextBox has focus will perform a paste).  In what context do you want to do this?
    Friday, November 24, 2006 7:10 PM
    Moderator
  • This was very helpful. Do you know how to use the Undo control to undo a change made? Thanks Alot
    Friday, November 24, 2006 8:57 PM
  • just press CTRL+Z or the control's Undo method, should it have one:

    this.theTextBox.Undo();

    Friday, November 24, 2006 9:04 PM
    Moderator