Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting multiple labels to transparent across 1.000 forms?

I skinned my software with Devexpress and I found that the labels were non-transparent causing them to have grey background.

There's just endless forms, so I was wondering whether there was a way to do this task (of setting labels to transparent) automatically.

I did a similar thing earlier, the Devexpress controls on the form had LookAndFeel.NativeStyle = True, I used Grep Search to replace it to False on all dfm forms. In the label's case however, the transparent property is not present.

Thank you.

like image 672
Rosenberg Avatar asked May 25 '11 15:05

Rosenberg


1 Answers

The global Screen variable keeps track of all forms:

procedure MakeLabelsTransparent(AParent: TWinControl);
var
  I: Integer;
begin
  with AParent do
    for I := 0 to ControlCount - 1 do
      if Controls[I] is TLabel then
        TLabel(Controls[I]).Transparent := True
      else if Controls[I] is TWinControl then
        MakeLabelsTransparent(TWinControl(Controls[I]));
end;

procedure TMainForm.ActiveFormChange(Sender: TObject);
begin
  with Screen do
    if (ActiveCustomForm <> nil) and (ActiveCustomForm.Tag = 0) then
    begin
      MakeLabelsTransparent(ActiveCustomForm);
      ActiveCustomForm.Tag := 1;
    end;
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
  Screen.OnActiveFormChange := ActiveFormChange;
end;

And if you have to use the Tag property for a particular form, then omit this check: it wouldn't really get that much slower.

like image 137
NGLN Avatar answered Sep 26 '22 08:09

NGLN