c# - 在 ToolStripTextBox (C#) 中检测来自剪贴板的粘贴

标签 c# clipboard paste wndproc

我需要检测用户是否将剪贴板中的文本粘贴到 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.

关于c# - 在 ToolStripTextBox (C#) 中检测来自剪贴板的粘贴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11846130/

相关文章:

c# - Visual Studio 2010 - 卸载 NuGet

java - 将 DefaultTableModel 数据复制到剪贴板

c# - 如何使用 C# 中的基本身份验证在 github 上创建要点

c# - 是什么导致此 ASP.NET 标记被视为字符串?

c++ - Visual Studio 2013 C++ 监 window 口 : arrays copy incorrectly to clipboard

bash - 从文件中提取信息并将其作为列添加到另一个文件中

python - os.system 提示圆括号

ios - Xamarin IOS CanPerformAction 不工作

c# - .NET/C# 上有一种 isset() 吗?

Python 3 Selenium |剪贴板不适用于 Windows 上的 headless chromedriver