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