VB Migration Partner


Previous | Index | Next 

[INFO] DIB images are copied and pasted as regular images

In VB6 you can copy and paste images in the Device Independent Bitmaps (DIB) format, as in this code:

    Clipboard.SetData Picture1.Picture, vbCFDIB
    Set Picture2.Picture = Clipboard.GetData(vbCFDIB)

The above code is migrated to VB.NET correctly, except that it uses the Clipboard6 object defined in the language support library:

    Clipboard6.SetData(Picture1.Picture, VBRUN.ClipBoardConstants.vbCFDIB)
    Picture2.Picture = Clipboard6.GetData(VBRUN.ClipBoardConstants.vbCFDIB)

Our tests show, however, that the .NET Clipboard has problems working with the DIB format and that the GetData method returns a MemoryStream object instead of an Image object, which in turn causes an exception to be thrown when this object is assigned to the Picture property of the Picture1 control.

To reduce the odds of a runtime error in your applications, the Clipboard6.GetData method treats the vbCFDIB format as if the vbCFBitmap format were specified instead. This isn’t usually a problem, because applications that copy images to the Clipboard in the DIB format usually copy them also in the raw BMP format; therefore in virtually all cases the GetData method retrieves the right image.

Along the same lines, when you pass the vbCFDIB format to the Clipboard6.SetData method, then the image is stored both in DIB format and in raw BMP format, so that other applications can retrieve the image in DIB format, if they need to.

If you don’t want the Clipboard6 object to perform these automatic conversions for you and prefer to be in full control of the DIB vs. BMP format used when copying and pasting images, then you should edit the converted VB.NET and use the My.Computer.Clipboard object instead, as in the following code:

    My.Computer.Clipboard.SetData(Picture1.Picture, DataFormats.Dib)
    Picture2.Picture = My.Computer.Clipbard.GetData(DataFormats.Dib)
Previous | Index | Next 

Follow Francesco Balena on VB6 migration’s group on


Read Microsoft Corp’s official case study of a VB6 conversion using VB Migration Partner.

Code Architects and its partners offers remote and onsite migration services.

More details

Subscribe to our free newsletter for useful VB6 migration tips and techniques.


To learn more about your VB6 applications, run VB6 Analyzer on your source code and send us the generated text file. You will receive a detailed report about your VB6 applications and how VB Migration Partner can help you to quickly and effectively migrate it to .NET.

Get free advice

A fully-working, time-limited Trial Edition of VB Migration Partner allows you to test it against your actual code

Get the Trial

The price of VB Migration Partner depends on the size of the VB6 application, the type of license, and other factors

Request a quote

Migrating a VB6 application in 10 easy steps

Comparing VB Migration Partner with Upgrade Wizard

Migration tools: Feature Comparison Table

All whitepapers