VB Migration Partner

KNOWLEDGE BASE - Forms and controls


Previous | Index | Next 

[PRB] Can’t mix VB graphic properties and GDI native calls

All VB6 graphic properties – including BackColor, ForeColor, DrawMode, DrawStyle, etc. – map directly to attributes of the underlying GDI device context. In other words, each assignment you make to one of these properties corresponds to an immediate call to one of the many GDI methods.

Because of this “direct” equivalence between VB6 graphic properties and GDI attributes, in most cases your legacy VB6 code can freely mix assignment to VB6 properties, calls a VB6 graphic methods, and calls to GDI methods (declared by a suitable Declare statement), as in this code:

        ' display a filled rectangle
        Picture1.FillColor = &HF0F0
        Rectangle Picture1.hDC, 10, 20, 200, 300        '  <-- Rectangle is a GDI method

You can migrated this code to VB.NET using VB Migration Partner:

        Picture1.FillColor = FromOleColor6(&HF0F0)
        Rectangle(Picture1.hDC, 10, 20, 200, 300)

However this code doesn’t behave like the VB6 code, because the graphic properties exposed by the VB6Form, VB6PictureBox, and VB6UserControl classes (defined in VB Migration Partner’s library – don’t map to GDI attributes.

In this specific example, the GDI Rectangle method is oblivious of the assignment to the FillColor property, and in fact the rectangle will be filled with the device context’s default fill color (usually white).

Unfortunately, there is no automatic or simple solution to this problem. You either have to use only VB6 methods or only GDI method, and can’t mix the two approaches.

Previous | Index | Next 




Follow Francesco Balena on VB6 migration’s group on

LinkedIn





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.

newsletter



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