Einzelnen Beitrag anzeigen

Benutzerbild von Uwe Raabe
Uwe Raabe

Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.452 Beiträge
 
Delphi 12 Athens
 
#5

AW: Hintergrundform abdunkeln, wenn andere Form Modal geöffnet wird?

  Alt 30. Apr 2024, 23:31
Ich hatte das mal auf diese Weise implementiert:
Delphi-Quellcode:
function ShowModalDimmed(Form: TForm; ParentForm: TForm = nil; Centered: Boolean = true; SpaceBelow: Integer = 0):
    TModalResult;
var
  Back: TForm;
  below: Integer;
  P: TPoint;
begin
  Back := TForm.Create(nil);
  try
    Back.Position := poDesigned;
    Back.BorderStyle := bsNone;
    Back.AlphaBlend := true;
    Back.AlphaBlendValue := 192;
    Back.Color := clBlack;
    if ParentForm <> nil then
      Back.SetBounds(ParentForm.Left, ParentForm.Top, ParentForm.Width, ParentForm.Height)
    else
      Back.SetBounds(0, 0, Screen.Width, Screen.Height);
    Back.Show;
    if Centered then begin
      P := TPoint.Create((Back.ClientWidth - Form.Width) div 2, (Back.ClientHeight - Form.Height) div 2);
      below := Back.ClientHeight - (P.Y + Form.Height);
      if below < SpaceBelow then begin
        P.Y := P.Y - (SpaceBelow - below);
        if P.Y < 0 then
          P.Y := 0;
      end;
      P := Back.ClientToScreen(P);
      Form.Position := poDesigned;
      Form.Left := P.X;
      Form.Top := P.Y;
    end;
    result := Form.ShowModal;
    Back.Hide;
  finally
    Back.Free;
  end;
end;
Uwe Raabe
Certified Delphi Master Developer
Embarcadero MVP
Blog: The Art of Delphi Programming
  Mit Zitat antworten Zitat