Windows Develop Bookmark and Share   
 index > Windows Forms General > Cut, Copy and Paste code in C#?
 

Cut, Copy and Paste code in C#?

Hey there,

I want to know simple code to cut/copy text from a richTextBox1 and to paste anywhere in the same richTextBox1.

Now, tell me what would be the code for that.?

Thanks, in advance.

Shaiff.

Shaiff  Tuesday, July 17, 2007 10:22 PM

Not sure if you have some specific criteria for this or not, but here is a small sample that puts text into the RTF control, selects some text, copies it, then pastes it somewhere else in the RTF control. This utilizes the "Copy" method (which will copy it to the clipboard), but there are other ways to do it if you don't want to put it on the clipboard.

Code Snippet

private void Form1_Load(object sender, EventArgs e)

{

rtb.Text = "This is some text to practice cut/copy/paste operations.";

}

private void button1_Click(object sender, EventArgs e)

{

rtb.Select(10, 20);

rtb.Copy();

rtb.SelectionStart = 50;

rtb.SelectionLength = 0;

rtb.Paste();

}

(FYI - There is also a "Cut" method on the RTF control.)

ARK88  Wednesday, July 18, 2007 12:28 AM

Not sure if you have some specific criteria for this or not, but here is a small sample that puts text into the RTF control, selects some text, copies it, then pastes it somewhere else in the RTF control. This utilizes the "Copy" method (which will copy it to the clipboard), but there are other ways to do it if you don't want to put it on the clipboard.

Code Snippet

private void Form1_Load(object sender, EventArgs e)

{

rtb.Text = "This is some text to practice cut/copy/paste operations.";

}

private void button1_Click(object sender, EventArgs e)

{

rtb.Select(10, 20);

rtb.Copy();

rtb.SelectionStart = 50;

rtb.SelectionLength = 0;

rtb.Paste();

}

(FYI - There is also a "Cut" method on the RTF control.)

ARK88  Wednesday, July 18, 2007 12:28 AM

You can use google to search for other answers

Custom Search

More Threads

• Vertical scroll for my panel
• How to fire particular Event from FormClosing
• getting windows xp app close buttons...
• common open dialog
• DataGridView Column Names and Lists
• Panel Autosizing
• Custom Date Format in DateTimePicker(WinForms)
• can any one help me
• Can anyone provid any sample code to detect changes of datasource data
• problems when using OpenFileDialog.showdialog()