SetData Method

See AlsoODIV17              ExampleQHTRSC>Low

Puts a picture in the operating environment Clipboard using the specified format.

Syntax

Clipboard.SetData data,[ format]

Remarks

The SetData method has these parts:

Part               Description

 

data               Picture (Image or Picture property) to place on the Clipboard.

format            One of the following Clipboard formats recognized by Visual Basic. If format is 0 or omitted, SetData automatically determines the format.

 

Symbolic constant   Value      Clipboard format

 

CF_BITMAP              2             Bitmap (.BMP files)

CF_METAFILE          3             Metafile (.WMF files)

CF_DIB                     8             Device-independent bitmap

CF_PALETTE            9             Color palette

 

For the CF_BITMAP format, any associated color palette will be copied to the Clipboard along with the bitmap.

 

Note  Symbolic constants for Clipboard format definitions can be found in the Visual Basic file CONSTANT.TXT. When placed in any module in a project, the symbolic names can be used in all your form and code modules.

 


See Also

Clipboard Object6WM59T

GetData MethodZIOQ42

GetFormat MethodNGJXI2


SetData Method Example

The example uses the SetData method to place a bitmap onto the Clipboard.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

 

Sub Form_Click ()

   Const CF_BITMAP = 2                   ' Define bitmap format.

   Dim Msg                               ' Declare variable.

   On Error Resume Next                  ' Set up error handling.

   Msg = "Choose OK to load a bitmap onto the Clipboard."

   MsgBox Msg                            ' Display message.

   Clipboard.Clear                       ' Clear Clipboard.

   Clipboard.SetData LoadPicture("PAPER.BMP") ' Get bitmap.

   If Err Then

      Msg = "Could not find the .BMP file."

      MsgBox Msg                         ' Display error message.

      Exit Sub

   End If

   Msg = "A bitmap is now on the Clipboard. Choose OK to copy "

   Msg = Msg & "the bitmap from the Clipboard to the form "

   MsgBox Msg                            ' Display message.

   Picture = Clipboard.GetData()         ' Copy from Clipboard.

   Msg = "Choose OK to clear the picture box."

   MsgBox Msg                            ' Display message.

   Picture = LoadPicture()               ' Clear picture box.

End Sub