實(shí)現(xiàn)該菜單功能主要有兩種方法:
第一種:通過發(fā)送擊鍵到應(yīng)用程序來實(shí)現(xiàn)。
先焦點(diǎn)定位到當(dāng)前活動(dòng)的RichTextBox,然后再通過發(fā)送擊鍵命令來實(shí)現(xiàn)操作功能
richTextBox1.Focus();
SendKeys.Send(
"^a"
);
//全選
"^c"
//復(fù)制
"^x"
//剪切
"^v"
//粘貼
第二種:直接通過命令操作剪貼板實(shí)現(xiàn)
Clipboard.SetData(DataFormats.Rtf, richTextBox1.SelectedRtf);
//復(fù)制RTF數(shù)據(jù)到剪貼板
richTextBox1.SelectedRtf=
""
;
//再把當(dāng)前選取的RTF內(nèi)容清除掉,當(dāng)前就實(shí)現(xiàn)剪切功能了.
richTextBox1.Paste();
//把剪貼板上的數(shù)據(jù)粘貼到目標(biāo)RichTextBox
//全選(其中全選又有兩種方式)
//設(shè)置先焦點(diǎn)定位到當(dāng)前活動(dòng)的RichTextBox,這一句很重要,否則它不能正確執(zhí)行
//另一種則是通過Select(int start,int length)方法來實(shí)現(xiàn)
richTextBox1.Select(0, richTextBox1.Rtf.Length);
//richTextBox1.Rtf.Length代表RichTextBox中文字的長度
//一種是直接采用NET框架當(dāng)中提供的SelectAll()方法,進(jìn)行全選
//richTextBox1.SelectAll();