Delphi: transparent controls become opaque on netbooks

For some reason, the transparent controls on the form become opaque on some computers. I have received reports that this is happening on the “Acer Netbook” and “Thinkpad x600.” The application is built using Delphi 2007.

It looks like this: link

For now, it should look like this: link

Opaque controls on the form are TLabels and TStaticTexts.

(I use TStaticText controls to identify areas that can be clicked because mouse messages for uncontrolled controls (such as shortcuts) go to the WM_NCHITTEST handler. The "button" below is black because I accidentally set its color to clNone, although it should not be visible at all.)

Why is this happening and how to prevent it (with the exception of workarounds, for example, rendering text on a background image)?

Edit: I was able to reproduce the problem on my laptop running Windows XP with 32-bit color and using certified ATI drivers.

+3
source share
5 answers

TImage TLabel ? , . TLabel , , TImage . , , .

( TLabel), , . , TWinControl ( TGraphicControl) . YMMV .

, , , - Windows API.

+8

. ( , Windows):

  • , 32. 16- , . , .

  • - , . , .

  • ( -) Windows 2000 - , - ?

, ( , , .) , .

+3

TForm TImage TLabel - , , TLabel.Transparent True.

VMWare Windows XP/Windows 7. , "Windows Classic" . Windows 7 Windows Aero, Windows Basic Windows Classic. "Windows Classic" . (Windows XP ).

TLabel Transparent, True . , , "Windows Classic" . - Transparent True, Object Inspector. , label Transparent: False, True. label Transparent True, . .dfm Transparent = True , .

Delphi 10.2 Tokyo.

+1

, , , , align with marginins . "" "" , DPI.

0

, .

My application uses TLabels instead of TButtons. At runtime, I create TShapes whose size matches the label. I set the OnMouseEnter and OnMouseLeave events to change the color of TShape. It worked fine on every machine that I tested, until it got to that particular XP installation, where I ran into an OP problem.

I finally found a solution that worked.

  for i := 0 to frm.ComponentCount-1 do begin
  if (frm.Components[i] is TLabel) and
     (((TLabel(frm.Components[i]).Tag > 999) and
     (Length(TLabel(frm.Components[i]).Caption) > 1) and (Assigned(TLabel(frm.Components[i]).OnClick))) or
     (TLabel(frm.Components[i]).Caption = 'Close')) then
    begin
      //setting this to false here, then to true at the bottom eliminates the "opaquing" problem
      TLabel(frm.Components[i]).Transparent := False;

      ls := TShape.Create(frm);
      ls.Name := 'ClickLabel' + IntToStr(i) + TWinControl(frm.Components[i]).Name;
      ls.Parent := TWinControl(frm.Components[i]).Parent;
      ls.Hint := TWinControl(frm.Components[i]).Hint;
      ls.ShowHint := True;
      ls.Top := TWinControl(frm.Components[i]).Top-4;
      ls.Left := TWinControl(frm.Components[i]).Left-7;
      ls.Width := TWinControl(frm.Components[i]).Width + 12;
      ls.Height := TWinControl(frm.Components[i]).Height + 8;
      ls.Shape := stRoundRect;   
      ls.BringToFront;
      TWinControl(frm.Components[i]).BringToFront;
      ls.Visible := TWinControl(frm.Components[i]).Visible;
      ls.Tag := TWinControl(frm.Components[i]).Tag;

      ls.OnMouseEnter := EvHandler.lblNavMouseEnter;
      ls.OnMouseLeave := EvHandler.lblNavMouseLeave;
      ls.Anchors := TLabel(frm.Components[i]).Anchors;

      ls.Pen.Width := 2;

      TLabel(frm.Components[i]).Transparent := True;
    end;
end;
0
source

Source: https://habr.com/ru/post/1706595/


All Articles