简体   繁体   English

C#:如何不断检查剪贴板上的复制文本

[英]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对象的示例和用法。

Clipboard event C# 剪贴板事件C#

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.

相关问题 C#-剪贴板挂钩检查要复制的数据是真正的图像还是文本? - C# - Clipboard hooking check if the data being copied is really image or a text? 在 selenium 按钮单击 C# 中的变量后,如何分配复制到剪贴板的字符串? - How can I assign string copied to clipboard after selenium button click to a variable in C#? 如何不断检查WinForms / C#中的内容? - How to constantly check something in WinForms/C#? 如何以编程方式访问剪贴板中复制的选择的地址 - How do I access programmatically the address of the copied selection from the clipboard 如何在C#中备份和还原系统剪贴板? - How do I backup and restore the system clipboard in C#? 如何将字符串的内容复制到C#中的剪贴板? - How do I copy the contents of a String to the clipboard in C#? 如何监控 C# 中的剪贴板变化? - How do I monitor clipboard changes in C#? 如何使用C#打印剪贴板中的图像? - How do I print an image that is in the clipboard using C#? 检查剪贴板中已复制的文本 - Check Clipboard for Copied texts 如何使用C#在剪贴板中设置文本,以便将每个文本粘贴到具有不同背景/字体颜色的excel中? - How do I set a text in clipboard using C# in order to past it into excel with different background/font color for each cell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM