[英]C#: How Do I Constantly Check the Clipboard for Copied Text
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. 谢谢。
Take a look at this answer, 看看这个答案,
It provides examples and usage of a Win32 API object called Clipboard monitor. 它提供了名为Clipboard monitor的Win32 API对象的示例和用法。
This solution would be a much cleaner and efficient way to achieve this result. 这种解决方案将是一种更加清洁和有效的方法来实现这一结果。
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!) 除了使用剪贴板监视API之外,请务必避免常见的陷阱,例如未能传递消息,以及未能从剪贴板通知中删除自己(即使您崩溃并且正在火上浇油,您应该从剪贴板通知链中删除自己!)
I have resources here, which explain how to avoid the common problems: http://www.clipboardextender.com/developing-clipboard-aware-programs-for-windows 我这里有资源,解释如何避免常见问题: http : //www.clipboardextender.com/developing-clipboard-aware-programs-for-windows
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.