C# 创建RichTextBox的右键菜单

        private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
this.contextMenuStrip1.SourceControl.Select();//先获取焦点,防止点两下才运行
            RichTextBox rtb = (RichTextBox)this.contextMenuStrip1.SourceControl;
            rtb.Copy();
        }

        
private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
this.contextMenuStrip1.SourceControl.Select();
            RichTextBox rtb 
= (RichTextBox)this.contextMenuStrip1.SourceControl;
            rtb.Paste();
        }

        
private void 剪切ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
this.contextMenuStrip1.SourceControl.Select();
            RichTextBox rtb 
= (RichTextBox)this.contextMenuStrip1.SourceControl;
            rtb.Cut();
        }

        
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
this.contextMenuStrip1.SourceControl.Select();
            RichTextBox rtb 
= (RichTextBox)this.contextMenuStrip1.SourceControl;
            rtb.SelectedText 
= "";
        }

        
private void 全选ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
this.contextMenuStrip1.SourceControl.Select();
            RichTextBox rtb 
= (RichTextBox)this.contextMenuStrip1.SourceControl;
            rtb.SelectAll();
        }

        
private void 撤销ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
this.contextMenuStrip1.SourceControl.Select();
            RichTextBox rtb 
= (RichTextBox)this.contextMenuStrip1.SourceControl;
            rtb.Undo();
        }
posted @ 2009-07-08 09:38  afish1984  阅读(1187)  评论(0编辑  收藏  举报