Export (0) Print
Expand All
Expand Minimize

Clipboard Object Changes in Visual Basic .NET

The Clipboard object in Visual Basic 6.0 has no direct equivalent in Visual Basic .NET. Although there is no direct mapping, the functionality of the Clipboard object can be duplicated using the System.Windows.Forms.Clipboard namespace.

During upgrade, any code that references the Clipboard object is not upgraded and must be rewritten. The following example shows how to modify code that uses the Clipboard object:

' Visual Basic 6.0 
Clipboard.Clear
Clipboard.SetText "hello", vbCFText

If Clipboard.GetFormat(vbCFText) Then
   Text1.Text = Clipboard.GetText(vbCFText)
End If

This can be rewritten as:

' Visual Basic .NET 
Dim datobj As New System.Windows.Forms.DataObject

datobj.SetData System.Windows.Forms.DataFormats.Text, "hello"
System.Windows.Forms.Clipboard.SetDataObject datobj

If System.Windows.Forms.Clipboard.GetDataObject.GetDataPresent( _
   System.Windows.Forms.DataFormats.Text) Then
   Text1.Text = System.Windows.Forms.Clipboard.GetDataObject.GetData( _
   System.Windows.Forms.DataFormats.Text)
End If

Clipboard Constant Equivalents

Visual Basic 6.0Visual Basic .NET Equivalent
vbCFBitmapSystem.Windows.Forms.DataFormats.Bitmap
vbCFDIBSystem.Windows.Forms.DataFormats.DIB
vbCFEMetafileSystem.Windows.Forms.DataFormats.EnhancedMetafile
vbCFFilesSystem.Windows.Forms.DataFormats.FileDrop
vbCFLinkNo equivalent. For more information, see Dynamic Data Exchange Changes in Visual Basic .NET.
vbCFMetafileSystem.Windows.Forms.DataFormats.MetafilePict
vbCFPaletteSystem.Windows.Forms.DataFormats.Palette
vbCFRTFSystem.Windows.Forms.DataFormats.Rtf
vbCFTextSystem.Windows.Forms.DataFormats.Text
Note   In addition to the formats listed above, Visual Basic .NET supports several clipboard formats that were not supported in Visual Basic 6.0.

See Also

Drag-and-Drop Operations and Clipboard Support | DataObject Class

Show:
© 2015 Microsoft