C# 问题:我的form下有多个textbox,请问菜单里的复制、粘贴、撤销、剪切的代码怎么写,谢谢!
3个回答
展开全部
这是我在用C#编写记事本时候用的代码,希望对你有帮助!
private void 撤销ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Undo();
恢复ToolStripMenuItem.Enabled = true;
}
private void 剪切ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Cut();
}
private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Copy();
剪切ToolStripMenuItem.Enabled = true;
if (复制ToolStripMenuItem.Enabled = true&&RichTextBox1.SelectedText!="")
{
剪切ToolStripMenuItem.Enabled = true;
复制ToolStripMenuItem.Enabled = true;
删除ToolStripMenuItem.Enabled = true;
清空ToolStripMenuItem.Enabled = true;
恢复ToolStripMenuItem.Enabled = true;
}
if (复制ToolStripMenuItem.Enabled = true && RichTextBox1.SelectedText == "")
{
剪切ToolStripMenuItem.Enabled = false;
复制ToolStripMenuItem.Enabled = false;
删除ToolStripMenuItem.Enabled = false;
清空ToolStripMenuItem.Enabled = false;
恢复ToolStripMenuItem.Enabled = false;
}
}
private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Paste();
//剪切ToolStripMenuItem.Enabled = true;
}
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.SelectedText = "";
}
private void 恢复ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Redo();
}
private void 撤销ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Undo();
恢复ToolStripMenuItem.Enabled = true;
}
private void 剪切ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Cut();
}
private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Copy();
剪切ToolStripMenuItem.Enabled = true;
if (复制ToolStripMenuItem.Enabled = true&&RichTextBox1.SelectedText!="")
{
剪切ToolStripMenuItem.Enabled = true;
复制ToolStripMenuItem.Enabled = true;
删除ToolStripMenuItem.Enabled = true;
清空ToolStripMenuItem.Enabled = true;
恢复ToolStripMenuItem.Enabled = true;
}
if (复制ToolStripMenuItem.Enabled = true && RichTextBox1.SelectedText == "")
{
剪切ToolStripMenuItem.Enabled = false;
复制ToolStripMenuItem.Enabled = false;
删除ToolStripMenuItem.Enabled = false;
清空ToolStripMenuItem.Enabled = false;
恢复ToolStripMenuItem.Enabled = false;
}
}
private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Paste();
//剪切ToolStripMenuItem.Enabled = true;
}
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.SelectedText = "";
}
private void 恢复ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Redo();
}
更多追问追答
追问
我说的是多个textbox,我的窗体没有richtextbox
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询