Fade all other windows of an application when a dialog is shown?

前端 未结 5 393
轮回少年
轮回少年 2021-01-30 18:33

How to dim / fade all other windows of an application in Delphi 2009.

Form has an AlphaBlend property, but it controls only transparency level. But it would be nice if

5条回答
  •  旧时难觅i
    2021-01-30 19:39

    I have done something similar for showing a modal form trying to keep the implementation as simple as possible. I don't know if this will fit your needs, but here it is:

    function ShowModalDimmed(Form: TForm; Centered: Boolean = true): TModalResult;
    var
      Back: TForm;
    begin
      Back := TForm.Create(nil);
      try
        Back.Position := poDesigned;
        Back.BorderStyle := bsNone;
        Back.AlphaBlend := true;
        Back.AlphaBlendValue := 192;
        Back.Color := clBlack;
        Back.SetBounds(0, 0, Screen.Width, Screen.Height);
        Back.Show;
        if Centered then begin
          Form.Left := (Back.ClientWidth - Form.Width) div 2;
          Form.Top := (Back.ClientHeight - Form.Height) div 2;
        end;
        result := Form.ShowModal;
      finally
        Back.Free;
      end;
    end;
    

提交回复
热议问题