How do i use keyboard shortcuts and use cut, copy, paste, and undo?  
Author Message
DeamonX





PostPosted: Visual C# General, How do i use keyboard shortcuts and use cut, copy, paste, and undo? Top

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.


Visual C#10  
 
 
ahmedilyas





PostPosted: Visual C# General, How do i use keyboard shortcuts and use cut, copy, paste, and undo? Top

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

}

}



 
 
Peter Ritchie





PostPosted: Visual C# General, How do i use keyboard shortcuts and use cut, copy, paste, and undo? Top

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

 
 
DeamonX





PostPosted: Visual C# General, How do i use keyboard shortcuts and use cut, copy, paste, and undo? Top

This was very helpful. Do you know how to use the Undo control to undo a change made Thanks Alot

 
 
ahmedilyas





PostPosted: Visual C# General, How do i use keyboard shortcuts and use cut, copy, paste, and undo? Top

just press CTRL+Z or the control's Undo method, should it have one:

this.theTextBox.Undo();