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();
        }

你可能感兴趣的:(text)