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

查看:1685
本文介绍了如何监控在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.

干杯,

编辑:如果使用Vista或更高版本,使用 AddClipboardFormatListener 在约翰Knoeller的回答,XP,必须使用较旧的,比较脆弱 SetClipboardViewer API,作为公认的答案。

If using Vista or later, use AddClipboardFormatListener as in John Knoeller's answer, for XP, have to use the older, more fragile SetClipboardViewer API, as in the accepted answer.

推荐答案

您可以使用的 SetClipboardViewer 通过WIN32 API提供的(通过的P / Invoke)。

You could use SetClipboardViewer provided by win32 API (through p/invoke).

下面是一个页面,其中包含code来设立一个在C#:<​​一href="http://www.$c$cguru.com/csharp/.net/net_general/tipstricks/article.php/c7315/">http://www.$c$cguru.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天全站免登陆