在ToolStripTextBox(C#)中检测剪贴板中的粘贴

我需要检测用户是否将剪贴板中的文本粘贴到ToolStripTextBox中.因此,我创建了一个继承自ToolStripTextBox的自定义控件.然后我想覆盖WndProc以捕获WM_PASTE消息,但我注意到没有WndProc可以覆盖.对于标准TextBox,所描述的方法工作正常.

有什么建议如何检测ToolStripTextBox上的剪贴板粘贴?

最佳答案 似乎无法触及ToolStripTextBox中的WndProc.我出于好奇搜索了一下,然后遇到了答案 –
https://stackoverflow.com/a/4688745/168719

如果使用ToolStripControlHost不是一个选项,那么对于需要自定义处理WndProc的场景,还有其他聪明的解决方案:

http://bytes.com/topic/c-sharp/answers/279168-toolstriptextbox-right-click

Nicholas Paldino [.NET/C# MVP]

I just noticed that. In order to get around this, you can get the
hosted TextBox by calling the TextBox property. Then, you should be
able to create a class derived from NativeWindow which overrides the
WndProc method to ignore the context menu message [or to intercept WM_PASTE, obviously…]
When you get the textbox property, get the handle, and assign the handle to your overridden NativeWindow class.

点赞