C#面编辑菜单时的实现“复制,粘贴,剪切,撤消”这些作用的代码怎样编写???
如用:privatevoid复制ToolStripMenuItem_Click(objectsender,EventArgse)……………………这后面的代码怎么写...
如用:
private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)……………………这后面的代码怎么写 展开
private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)……………………这后面的代码怎么写 展开
1个回答
展开全部
这是我用richTextBox控件做的,你参考下:
//文本的撤消
private void editUndo_Click(object sender, System.EventArgs e)
{
this.richTextBox1.Undo();
}
//文本的剪切
private void editTrim_Click(object sender, System.EventArgs e)
{
if(richTextBox1.SelectedText.Length > 0)
{
try
{
this.richTextBox1.Cut();
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
//文本的复制
private void editCopy_Click(object sender, System.EventArgs e)
{
if(richTextBox1.SelectedText.Equals(""))
return;
Clipboard.SetDataObject(richTextBox1.SelectedText,true);
}
//文本的粘贴
private void editPaste_Click(object sender, System.EventArgs e)
{
if(Clipboard.GetDataObject().GetDataPresent(DataFormats.Text))
{
this.editPaste.Enabled = true;
this.richTextBox1.Paste();
}
else
{
this.editPaste.Enabled = false;
}
}
// 这样写
private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)
{
// 判断是否选中文本
if(richTextBox1.SelectedText.Equals(""))
return;
Clipboard.SetDataObject(richTextBox1.SelectedText, true);
}
//文本的撤消
private void editUndo_Click(object sender, System.EventArgs e)
{
this.richTextBox1.Undo();
}
//文本的剪切
private void editTrim_Click(object sender, System.EventArgs e)
{
if(richTextBox1.SelectedText.Length > 0)
{
try
{
this.richTextBox1.Cut();
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
//文本的复制
private void editCopy_Click(object sender, System.EventArgs e)
{
if(richTextBox1.SelectedText.Equals(""))
return;
Clipboard.SetDataObject(richTextBox1.SelectedText,true);
}
//文本的粘贴
private void editPaste_Click(object sender, System.EventArgs e)
{
if(Clipboard.GetDataObject().GetDataPresent(DataFormats.Text))
{
this.editPaste.Enabled = true;
this.richTextBox1.Paste();
}
else
{
this.editPaste.Enabled = false;
}
}
// 这样写
private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)
{
// 判断是否选中文本
if(richTextBox1.SelectedText.Equals(""))
return;
Clipboard.SetDataObject(richTextBox1.SelectedText, true);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询