tags:

views:

1061

answers:

3

For some reason, transparent controls on a form turn opaque on some computers. I got reports of it happening on an "Acer Netbook" and a "Thinkpad x600". The application is built with Delphi 2007.

This is what it looks like: link

While it should look like this: link

The opaque controls on the form are TLabels and TStaticTexts.

(I use TStaticText controls to define clickable areas because mouse messages to handle-less controls (like Labels) go to the WM_NCHITTEST handler. The "button" on the bottom is black because I accidentally set its color to clNone, although it shouldn't be visible at all.)

Why does it happen and how to prevent this (other than workarounds like rendering the text to the background image)?

Edit: I managed to reproduce the problem on my laptop, which is running Windows XP in 32-bit color, and using certified ATI drivers.

+3  A: 

This has nothing to do with the brand of the system as such. In the order of likelihood, check these (assuming you're talking about Windows systems):

  • Transparency requires the display bit depth to be 32. If the display is set to 16-bit color, you can't draw transparent controls. User fixable, you should not autoswitch modes.

  • Video driver issue - ensure the users have the manufacturer-recommended video drivers. If those fail, try the latest ones.

  • Transparency (alpha-blending, actually) is only supported on Windows 2000 or higher - are you sure they're not running something older?

It would help a lot if you got more data from your users (or if you have that data, please post it.) We're shooting blind here since you didn't even mention the OS used.

Mihai Limbășan
The TLabel actually draws on its parent and is not rendered transparent by windows so I don't believe it is a driver issue. I am pretty sure the TLabel has had the transparent property since at least Delphi 3, which was prior to Windows 2000).
Jim McKeeth
That's true, didn't think of that, Delphi doesn't use alpha for labels (in which case it's most likely a driver issue.) We still don't have enough information - it may well be the 16-bit or paletted video mode issue coupled with not enough available colors.
Mihai Limbășan
I managed to reproduce the problem on my laptop, which is running Windows XP in 32-bit color. It's also using certified ATI drivers, so I don't think any of the points you specified apply...
CyberShadow
+4  A: 

Is there a TImage between the TLabel and the form? If that is the case then set the form's color to black. When you set a TLabel to transparent it draws it on its parent, and a TImage cannot have child controls. In effect it is rendering the color of the form onto the label since the form is the parent.

Two other possible workarounds include paining the image directly onto the form (not using a TLabel) but I don't know if that would work. Another would be to create your own image control that descends from TWinControl (instead of TGraphicControl) and that can contain child controls. YMMV on those solutions though.

I suspect the reason it doesn't work on some machines is the underlying Windows API library is different.

Jim McKeeth
The first workaround didn't work, and I couldn't be bothered to do the second, so I just hacked around the problem with your suggestion to set the labels' background color. I'll need to do the same for an application with a non-solid background, though, so I'll probably write something to iterate through all labels and draw them on the form manually.
CyberShadow
Oh, and yes, there is a TImage between the TLabel and the form. Beats me why it works on my Vista machine and on another XP machine, but doesn't work on other XP machines...
CyberShadow
A: 

while not a perfect solution, but would work better in handling your transparency issue would be to not use transparency at all, set the label background color to match that of the background, then use the align with margins property and set your margins to position the labels on the form. For the next, close and minimize buttons, I would make those separate graphics to avoid any font or DPI problems.

skamradt
The close/minimize buttons, as well as the "Next" button, are actually rendered on the underlying TImage. I use empty TStaticText controls to capture mouse messages.
CyberShadow
I once use a hotspot component to do just what your asking for. I'm not certain, but this is the one http://www.torry.net/vcl/graphics/other/amhotspot.zip .. you might have to make slight adjustments to handle your version of delphi, but it should work.
skamradt