一佳一

记录像1+1一样简洁的代码

导航

C# 复制 粘贴 剪切 撤销

Posted on 2013-03-20 17:01  一佳一  阅读(690)  评论(0编辑  收藏  举报

//复制
try
{
this.Cursor = Cursors.WaitCursor;
string strTemp = richTextBoxSendInfo.SelectedText;
//获取RichTextBox中选中的文字
if (strTemp.Equals("")) //判断是否为空
return;
Clipboard.Clear();//清除原有剪切板中内容
Clipboard.SetText(strTemp);//将文字添加到剪切板中,还添加Object类型数据
this.Cursor = Cursors.Default;
}
catch (System.Exception ex)
{
this.Cursor = Cursors.Default;
CommonFunc.DisplayException(ex);
}

//粘贴
try
{
this.Cursor = Cursors.WaitCursor;
this.richTextBoxSendInfo.Paste();//粘贴
this.Cursor = Cursors.Default;
}
catch (System.Exception ex)
{
this.Cursor = Cursors.Default;
CommonFunc.DisplayException(ex);
}

//剪切
try
{
this.Cursor = Cursors.WaitCursor;
string strTemp = richTextBoxSendInfo.SelectedText;
if (strTemp.Equals(""))
return;
Clipboard.Clear();
richTextBoxSendInfo.Cut();
this.Cursor = Cursors.Default;
}
catch (System.Exception ex)
{
this.Cursor = Cursors.Default;
CommonFunc.DisplayException(ex);
}

//撤销
try
{
this.Cursor = Cursors.WaitCursor;
richTextBoxSendInfo.Undo();
this.Cursor = Cursors.Default;
}
catch (System.Exception ex)
{
this.Cursor = Cursors.Default;
CommonFunc.DisplayException(ex);
}