Visual Basic Concepts

Checking the Data Formats on the Clipboard

See Also

You can use the GetFormat method to determine whether the data on the Clipboard is in a particular format. For example, you can disable the Paste command depending on whether the data on the Clipboard is compatible with the currently active control.

Private Sub mnuEdit_Click ()
' Click event for the Edit menu.
   mnuCut.Enabled = True
   mnuCopy.Enabled = True
   mnuPaste.Enabled = False
   If TypeOf Screen.ActiveControl Is TextBox Then
      If Clipboard.GetFormat(vbCFText) Then mnuPaste.Enabled = True
   ElseIf TypeOf Screen.ActiveControl Is ComboBox Then
      If Clipboard.GetFormat(vbCFText) Then mnuPaste.Enabled = True
   ElseIf TypeOf Screen.ActiveControl Is ListBox Then
      If Clipboard.GetFormat(vbCFText) Then mnuPaste.Enabled = True
   ElseIf TypeOf Screen.ActiveControl Is PictureBox _
         Then
      If Clipboard.GetFormat(vbCFBitmap) Then mnuPaste.Enabled = True
   Else
      ' Can't cut or copy from the other types 
      '   of controls.
      mnuCut.Enabled = False
      mnuCopy.Enabled = False
   End If
End Sub

Note   You might also want to check for other data formats with the constants vbCFPalette, vbCFDIB, and vbCFMetafile. If you want to replace a picture’s palette using Clipboard operations, you should request vbCFBitmap rather than vbCFDIB from the Clipboard. See "Working with 256 Colors" later in this chapter for more information on working with the color palette.

For More Information   See "Clipboard Object" in the Language Reference.