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