如何监视C#中剪贴板内容的变化? [英] How do I monitor clipboard content changes in C#?

查看:162
本文介绍了如何监视C#中剪贴板内容的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在我的C#程序中具有此功能:当用户执行 Ctrl + 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.

我可以从 System.Windows.Forms.Clipboard ,但是,我不知道如何监视剪贴板中的内容更改。

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.

如果使用Windows Vista或更高版本,请按照John Knoeller的回答使用 AddClipboardFormatListener ,对于Windows XP,我必须使用较旧的,更易碎的 SetClipboardViewer API,如已接受的答案一样。

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.

推荐答案

您可以使用 SetClipboardViewer

此处是包含代码的页面在C#中进行设置: http:// www .codeguru.com / csharp / .net / net_general / tipstricks / article.php / c7315 /

Here is a page which contains code to set one up in C#: http://www.codeguru.com/csharp/.net/net_general/tipstricks/article.php/c7315/

这篇关于如何监视C#中剪贴板内容的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆