如何重写拷贝和粘贴的RichTextBox [英] How to override copy and paste in richtextbox
本文介绍了如何重写拷贝和粘贴的RichTextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何可以覆盖一个RichTextBox C#应用程序的复制/粘贴功能。
包括CTRL-C / CTRL-V并右击复制/粘贴。
How can I override the copy/paste functions in a Richtextbox C# application. Including ctrl-c/ctrl-v and right click copy/paste.
这是WPF的RichTextBox。
It's WPF richtextBox.
推荐答案
要覆盖命令功能:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Control | Keys.C))
{
//your implementation
return true;
}
else if (keyData == (Keys.Control | Keys.V))
{
//your implementation
return true;
}
else
{
return base.ProcessCmdKey(ref msg, keyData);
}
}
和右键单击不在一个WinForms RichTextBox的支持
And right-clicking is not supported in a Winforms RichTextBox
- 编辑 -
实现为时已晚,这是一个WPF问题。在WPF做到这一点,你需要附加一个自定义的复制和粘贴处理程序:
Realized too late this was a WPF question. To do this in WPF you will need to attach a custom Copy and Paste handler:
DataObject.AddPastingHandler(myRichTextBox, MyPasteCommand);
DataObject.AddCopyingHandler(myRichTextBox, MyCopyCommand);
private void MyPasteCommand(object sender, DataObjectEventArgs e)
{
//do stuff
}
private void MyCopyCommand(object sender, DataObjectEventArgs e)
{
//do stuff
}
这篇关于如何重写拷贝和粘贴的RichTextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文