Brandon
Brandon

Reputation: 31

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.

Upvotes: 3

Views: 1098

Answers (2)

Chris Thornton
Chris Thornton

Reputation: 15817

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

Upvotes: 1

Taylor Bird
Taylor Bird

Reputation: 8017

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.

Upvotes: 8

Related Questions