Question
How do I monitor clipboard content changes in C#?
I want to have this feature in my C# program: When the user do Ctrl + C or Copy anywhere (i.e. when the clipboard content changes), my program will get notified, and check whether the content met certain criteria, if so, become the active program, and process the content, etc.
I can get the contents out from System.Windows.Forms.Clipboard
, however, I don't know how to monitor the content changes from the clipboard.
If using Windows Vista or later, use AddClipboardFormatListener
as in John Knoeller's answer, for Windows XP, I have to use the older, more fragile SetClipboardViewer
API, as in the accepted answer.