Microsoft KB Archive/78073

= PRB: Clipboard.SetData Gives Invalid Format Message with Icon =

Article ID: 78073

Article Last Modified on 12/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 1.0 Standard Edition
 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q78073



SYMPTOMS
If you use the Visual Basic LoadPicture function to load an icon file (.ICO) into a picture control, and then attempt to copy that picture control's picture to the Clipboard by using the SetData method, the following error message is displayed regardless of the format specified in SetData method:

Invalid Clipboard Format

This error also occurs if you attempt to load an icon file directly onto the Clipboard by using this code: ClipBoard.SetData LoadPicture(&quot;c:\vb\icons\arrows\arw01rt.ico&quot;)



CAUSE
The Microsoft Windows Clipboard in Windows has no CF_ICON format, so the Clipboard cannot be assigned Icons.



STATUS
This behavior is by design in Microsoft Windows Clipboard.



WORKAROUND
To work around the problem, set the picture control's Autoredraw property to True (-1) and use the Picture control's Image property in the SetData method rather than the Picture control's picture property.

'*** This code will fail with the error &quot;Invalid Clipboard Format&quot; *** Picture1.Picture = LoadPicture(&quot;c:\vb\icons\arrows\arw01rt.ico&quot;) Clipboard.SetData Picture1.Picture, 2 '*** This code will avoid the error *** Picture1.Autoredraw = -1 Picture1.Picture = LoadPicture(&quot;c:\vb\icons\arrows\arw01rt.ico&quot;) Clipboard.SetData Picture1.Image, 2 '*** This code will also work *** Picture1.Picture = LoadPicture(&quot;c:\vb\icons\arrows\arw01rt.ico&quot;) Picture1.Picture = Picture1.Image Clipboard.SetData Picture1.Picture, 2

Additional query words: 2.00 3.00

Keywords: kbprb KB78073

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.