简体   繁体   中英

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 event 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!)

I have resources here, which explain how to avoid the common problems: http://www.clipboardextender.com/developing-clipboard-aware-programs-for-windows

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM