gpt4 book ai didi

vb.net - 请求的剪贴板操作失败

转载 作者:行者123 更新时间:2023-12-01 10:13:33 33 4
gpt4 key购买 nike

我一直在使用 vb.net 2003,有时会出现此错误。谁能知道这个错误是如何产生的以及如何解决它?

错误:请求的剪贴板操作失败

最佳答案

我在谷歌上搜索了这个问题,看看我会看到什么,很多人都问过这个问题,但没有一个人得到可靠的答案......
于是我去MSDN文档,找到了一个注释,解释了大多数问这个问题的人是怎么描述的……这种症状通常出现在代码运行时用户切换到另一个应用程序时。该注释引用如下,文档链接如下:

All Windows-based applications sharethe system Clipboard, so the contentsare subject to change when you switchto another application.

An object must be serializable for itto be put on the Clipboard. If youpass a non-serializable object to aClipboard method, the method will failwithout throwing an exception. SeeSystem.Runtime.Serialization for moreinformation on serialization. If yourtarget application requires a veryspecific data format, the headersadded to the data in the serializationprocess may prevent the applicationfrom recognizing your data. Topreserve your data format, add yourdata as a Byte array to a MemoryStreamand pass the MemoryStream to theSetData method.

The Clipboard class can only be usedin threads set to single threadapartment (STA) mode. To use thisclass, ensure that your Main method ismarked with the STAThreadAttributeattribute.

Special considerations may benecessary when using the metafileformat with the Clipboard. Due to alimitation in the currentimplementation of the DataObjectclass, the metafile format used by the.NET Framework may not be recognizedby applications that use an oldermetafile format. In this case, youmust interoperate with the Win32Clipboard application programminginterfaces (APIs). For moreinformation, see article 323530,"Metafiles on Clipboard Are NotVisible to All Applications," in theMicrosoft Knowledge Base athttp://support.microsoft.com.


http://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard.aspx
有趣的是,这让我在自己的一个应用程序中注意到的一种奇怪行为变得有意义。我有一个写入 Excel 电子表格的应用程序(实际上,对数百个电子表格,每个修改数百个单元格)。我根本不使用剪贴板,只使用用于 excel 的 Interop API,但是当它运行时,每次创建新电子表格时我的剪贴板都会清除。就我而言,Excel 正在弄乱剪贴板,即使它没有明显的理由这样做。我将其归结为我们凡人永远无法理解的那些神秘的 Windows 现象之一。
无论如何,由于您的问题,我想我明白我的问题,所以 +1 给你帮助我。

关于vb.net - 请求的剪贴板操作失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3411576/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com