Previous | Index | Next 

[PRB] Image controls whose Picture property is Nothing aren't transparent

In VB6, an Image control whose Picture property is Nothing has a transparent background: you can see "through" it but the Image control still receives mouse events. This technique is often used by VB6 developers to create clickable "hot spots" over a form or a background image. In this case, the Image's BorderStyle property is usually set to 0-None, in which case the Image control becomes invisible, even though it receives mouse events.

The problem in converting these controls is that .NET doesn't support Image controls with transparent background. Setting the control's Visible property to False doesn't help, because an invisible .NET control doesn't receive mouse events.

VB Migration Partner solves the problem and converts the application correctly by setting the Image control's Visible property to False and manually forwarding all mouse events to the Image control. However, it is important to bear in mind that this arrangement works only if the BorderStyle property is also set to 0-None.

This trick doesn’t work if the Image control’s BorderStyle property is set to 1-FixedSingle. For example, a VB6 application might use such a control to draw a frame around a rectangular area on a form. In this case, the converted VB.NET displays a "blank" but opaque Image control that hides what is under it. Unfortunately, there is no definitive solution to this issue, even though the following two "half-solutions" should work in the majority of cases.

  1. If the application doesn't need to detect mouse activity over the Image control you can replace this control – in the original VB6 program – with a rectangular Shape control whose BorderWidth property is set to 1 or 2 pixels.
  2. If the application does need to detect mouse activity over the Image control, you can manually copy the underlying pixels to the Image.Picture property, for example using a PaintPicture method.


Previous | Index | Next