Cut, Copy, Paste Code and Undo Code in Windows app for a Text Box a

Raj.Trivedi
Posted by Raj.Trivedi under C# category on | Points: 40 | Views : 3155
Hello Friends,

This code will helps us to use Cut, Copy, Paste and Undo functionality

I have use a rich text box here you can use normal text box as well

private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
if (richTextBox1.SelectionLength > 0) richTextBox1.Copy();
}

// This will allow us to paste the text written in the text box.This will only work after you select the text in the Rich text box

private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Paste();
}

// This will allow us to cut the text written in the text box.This will only work after you select the text in the Rich text box
private void cutToolStripMenuItem_Click(object sender, EventArgs e)
{
if (richTextBox1.SelectedText != "") richTextBox1.Cut();
}

// This will allow us to undo the changes in the text box.
private void undoToolStripMenuItem_Click(object sender, EventArgs e)
{
if (richTextBox1.CanUndo == true) richTextBox1.Undo();
}

Comments or Responses

Login to post response