如何使用C#清除剪贴板内容
我有一个应用程序,我使用剪贴板进行复制和粘贴操作。对于复制,我使用了以下代码:
Clipboard.Clear();
const byte VK_CONTROL = 0x11;
keybd_event(VK_CONTROL, 0, 0, 0);
keybd_event(0x43, 0, 0, 0); // Send the C key (43 is "C")
keybd_event(0x43, 0, CONST_KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, 0, CONST_KEYEVENTF_KEYUP, 0);
但它给出了一个错误,指出无法执行剪贴板操作,并且我无法粘贴它。它抛出异常。
如何解决此问题,或者在复制之前是否有其他方法可以清除剪贴板内容?
I have an application where I am using the clipboard for copy and paste operations. For copying I have used this code:
Clipboard.Clear();
const byte VK_CONTROL = 0x11;
keybd_event(VK_CONTROL, 0, 0, 0);
keybd_event(0x43, 0, 0, 0); // Send the C key (43 is "C")
keybd_event(0x43, 0, CONST_KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, 0, CONST_KEYEVENTF_KEYUP, 0);
But it's giving an error saying Unable to perform the clipboard action, and I am unable to paste it. It's throwing an exception.
How do I fix this issue or are there some other ways to clear the clipboard content before we copy?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用:
请参阅 MSDN 文章 剪贴板类 ( System.Windows.Forms)。
Use:
See the MSDN article Clipboard Class (System.Windows.Forms).
我已经使用 Win32 API 调用(清空剪贴板功能)。
I have done it using Win32 API calls (EmptyClipboard function).
MSDN
MSDN
我知道这是一个较旧的线程,但我遇到了这个问题,这非常令人恼火。能够使用这个解决。
在课堂上
我想清除剪贴板的地方
I know this is an older thread but I came upon this problem and it was very irritating. Was able to resolve using this.
Inside of Class
Where I wanted to Clear the Clipboard