Previous | Index | Next 

[PRB] Mouse event aren’t received by transparent Image and Label controls

In VB6, Image controls whose Picture property is Nothing and Label controls with null caption and BackStyle set to 0-Transparent have transparent background: you can see "through" them even if the control receive mouse events. This technique is often used by VB6 developers to create clickable "hot spots" over a form or a background image.

The problem in converting these controls is that these controls aren’t transparent at all after the migration to VB2005. You actually need to make them invisible only by setting their Visible property to False, but this remedy prevents the controls from receiving mouse events. VB Migration Partner handles this case by making the control invisible and manually forwarding mouse events to them.

You usually don’t need to do anything to have the VB2005 code work correctly, except in the following scenario: you have a form with an Image control on it that contains a background image and then many transparent Image or Label controls that work as hot spots. In this case, in fact, by default VB Migration Partner sends the mouse event to the background Image control and fails to forward it to the transparent Image controls.

You can solve this problem in two ways: by replacing the background Image control with a PictureBox or by setting the background Image control’s IsBackgroundControl property. Setting this special property – exposed by the VB6Image and VB6Label controls – to True forces VB Migration Partner to search other transparent controls in the same container – the form, usually – and correctly forwards all mouse events. The easiest way to set this property is by means of a WriteProperty pragma:

        '## imgBack.WriteProperty IsBackgroundControl, True


Previous | Index | Next