//剪切/复制/粘贴
private void toolStripMenuItem36_Click(object sender, EventArgs e)
{
KeyMouseJQ(rtboxJkzd);
}
private void toolStripMenuItem23_Click(object sender, EventArgs e)
{
KeyMouseFZ(rtboxJkzd);
}
private void toolStripMenuItem24_Click(object sender, EventArgs e)
{
KeyMouseZT(rtboxJkzd);
}
//剪切 2020/05/13 add zx
public void KeyMouseJQ(RichTextBox rtb)
{
string strCopyText = rtb.SelectedText;
if (!string.IsNullOrEmpty(strCopyText))
{
Clipboard.SetDataObject(strCopyText);
IDataObject iData = Clipboard.GetDataObject();
string strPast = (String)iData.GetData(DataFormats.Text);
string strStar = rtb.SelectionStart.ToString();//鼠标当前位置
rtb.Text = rtb.Text.Remove(Convert.ToInt32(strStar), strPast.Length);
//设置粘贴后鼠标的节点位置
rtb.Select(Int32.Parse(strStar), 0);
rtb.ScrollToCaret(); //滚动到控件光标处
}
}
//复制 2020/05/13 add zx
public void KeyMouseFZ(RichTextBox rtb)
{
string strCopyText = rtb.SelectedText;
if (!string.IsNullOrEmpty(strCopyText))
{
Clipboard.SetDataObject(strCopyText);
}
}
//粘贴 2020/05/13 add zx
public void KeyMouseZT(RichTextBox rtb)
{
IDataObject iData = Clipboard.GetDataObject();
if (iData.GetDataPresent(DataFormats.Text))
{
string strPast = (String)iData.GetData(DataFormats.Text);
string strStar = rtb.SelectionStart.ToString();//鼠标当前位置
rtb.Text = rtb.Text.Insert(rtb.SelectionStart, strPast);
//设置粘贴后鼠标的节点位置
rtb.Select(Int32.Parse(strStar) + strPast.Length, 0);
rtb.ScrollToCaret(); //滚动到控件光标处
}
}