C#:如何不断检查剪贴板中是否有复制的文本
我需要帮助不断地循环检查剪贴板或其他内容以查找复制的文本。基本上我有一个粘贴按钮,但我只希望在将文本复制到剪贴板时启用它,并在没有复制任何文本时禁用它。我知道我必须使用:
Clipboard.ContainsText
检查是否已将文本复制到剪贴板,但我需要帮助制作循环或始终检查的内容。
谢谢。
I need help checking the clipboard constantly in a loop or something for copied text. Basically I have a paste button, but I only want it enabled when I have text copied to my clipboard and disabled when I don't have any text copied. I know I have to use:
Clipboard.ContainsText
to check if I have text copied to my clipboard, but I need help making a loop or something to always check.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看这个答案,
它提供了称为剪贴板监视器的 Win32 API 对象的示例和用法。
剪贴板事件 C#
此解决方案将是实现此结果的更干净、更有效的方法。
Take a look at this answer,
It provides examples and usage of a Win32 API object called Clipboard monitor.
Clipboard event C#
This solution would be a much cleaner and efficient way to achieve this result.
在使用剪贴板监控 API 的同时,请务必避免常见的陷阱,例如无法传递消息以及无法将自己从剪贴板通知中删除(即使您崩溃并着火了,您也应该将自己从剪贴板通知链中删除) !)
我这里有资源,解释了如何避免常见问题:
http://www.clipboardextender.com/developing-clipboard-aware-programs -for-windows
Along with using the clipboard monitoring API, be sure to avoid common pitfalls such as failing to pass messages, and failing to remove yourself from clipboard notification (even if you crash and are going down in flames, you should remove yourself from the clipboard notification chain!)
I have resources here, which explain how to avoid the common problems:
http://www.clipboardextender.com/developing-clipboard-aware-programs-for-windows