[英]Shortcuts Ctrl+C Ctrl+V dont work in Textboxes if MenuStrip has this Shortcuts set
Goal: A Menustrip with Copy and Paste and the user shall see the Shortcut-Keys. 目标:使用复制和粘贴的Menustrip,用户将看到快捷键。
Problem: If you have a MenuStrip and set the ShortcutKeys the are "catched" by the Menu but no longer by the Textboxes. 问题:如果你有一个MenuStrip并设置了ShortcutKeys,它们被菜单“捕获”但不再被文本框“捕获”。 This means you cannot use Ctrl+C / V in the Textboxes - only by Right-Click. 这意味着您不能在文本框中使用Ctrl + C / V - 只能通过右键单击。 If you remove the Shortcuts the Textboxes work fine. 如果删除快捷方式,文本框工作正常。
Why is that? 这是为什么? Whats the solution if I dont want to name the Entry "Copy______Ctrl+C"? 如果我不想将条目命名为“复制______ Ctrl + C”,那该解决方案是什么?
Example Project: http://www.file-upload.net/download-4098087/MenuBlocksSTRG.zip.html 示例项目: http : //www.file-upload.net/download-4098087/MenuBlocksSTRG.zip.html
MSDN is down ATM i found this links: MSDN已关机ATM我发现此链接:
This should work for copy, and you can take care of paste in same way: 这应该适用于复制,你可以用同样的方式处理粘贴:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Control | Keys.C) && textBox1.ContainsFocus)
{
Clipboard.SetText(textBox1.SelectedText);
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
If it still matters, the simple solution might be: Show only the shortcut keys text, as in the image. 如果它仍然重要,简单的解决方案可能是:只显示快捷键文本,如图像中所示。
In the TextBox set ShortcutsEnabled to true. 在TextBox中将ShortcutsEnabled设置为true。 That's all! 就这样!
You probably have to handle things yourself in those cases. 在这些情况下,您可能必须自己处理事情。
Simple example: 简单的例子:
private void copyToolStripMenuItem_Click(object sender, EventArgs e) {
if (this.ActiveControl is TextBox) {
Clipboard.SetText(((TextBox)this.ActiveControl).SelectedText);
} else {
// do your menu Edit-Copy code here
}
}
private void pasteToolStripMenuItem_Click(object sender, EventArgs e) {
if (this.ActiveControl is TextBox) {
((TextBox)this.ActiveControl).SelectedText = Clipboard.GetText();
} else {
// do you menu Edit-Paste code here
}
}
You need something like this? 你需要这样的东西吗?
ToolStripMenuItem Quit = new ToolStripMenuItem();
Quit.Name = "quitToolStripMenuItem";
Quit.Text = "&Quit";
Quit.ShortcutKeys = Keys.Alt | Keys.F4;
Quit.Click += new EventHandler(quitToolStripMenuItem_Click);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.