Advertisement
carlosfeitozafilho

UFormBlender.pas

Jun 18th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.25 KB | None | 0 0
  1. unit UFormBlender;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls;
  8.  
  9. type
  10.   TFormBlender = class(TForm)
  11.     Temporizador: TTimer;
  12.     procedure FormCreate(Sender: TObject);
  13.     procedure TemporizadorTimer(Sender: TObject);
  14.     procedure FormShow(Sender: TObject);
  15.   private
  16.     { Private declarations }
  17.     FInternalForm: TFormClass;
  18.   public
  19.     { Public declarations }
  20.     class function ShowMe(AOwner: TForm; AInternalForm: TFormClass): TModalResult;
  21.   end;
  22.  
  23. implementation
  24.  
  25. {$R *.dfm}
  26.  
  27. procedure TFormBlender.FormCreate(Sender: TObject);
  28. var
  29.   HOffset: Word;
  30.   VOffset: Word;
  31. begin
  32.   // Isso vai falhar de acordo com o tipo de janela ter ou não uma borda
  33.   // redimensionável. Mas isso é só um exemplo! Corra atrás de saber o que é
  34.   // GetSystemMetrics, SM_CXSIZEFRAME, SM_CXBORDER, SM_CYSIZEFRAME e SM_CYBORDER
  35.   HOffset := GetSystemMetrics(SM_CXSIZEFRAME) - GetSystemMetrics(SM_CXBORDER);
  36.   VOffset := GetSystemMetrics(SM_CYSIZEFRAME) - GetSystemMetrics(SM_CYBORDER);
  37.  
  38.   Top := TForm(Owner).Top;
  39.   Left := TForm(Owner).Left + HOffset;
  40.   Height := TForm(Owner).Height - VOffset;
  41.   Width := TForm(Owner).Width - 2 * HOffset;;
  42. end;
  43.  
  44. procedure TFormBlender.FormShow(Sender: TObject);
  45. begin
  46.   Temporizador.Enabled := True;
  47. end;
  48.  
  49. class function TFormBlender.ShowMe(AOwner: TForm; AInternalForm: TFormClass): TModalResult;
  50. begin
  51.   with Self.Create(AOwner) do
  52.     try
  53.       FInternalForm := AInternalForm;
  54.       Result := ShowModal;
  55.     finally
  56.       Close;
  57.       Free;
  58.     end;
  59. end;
  60.  
  61. procedure TFormBlender.TemporizadorTimer(Sender: TObject);
  62. begin
  63.   Temporizador.Enabled := False;
  64.   with FInternalForm.Create(Self) do
  65.     try
  66.       // Configura o form interno para que ele não tenha bordas
  67.       BorderStyle := bsNone;
  68.  
  69.       // Centraliza o form interno
  70.       Top := Self.Top + Self.Height div 2 - Height div 2;
  71.       Left := Self.Left + Self.Width div 2 - Width div 2;
  72.  
  73.       // Ao atribuir Self.ModalResult, TFormBlender vai fechar e retornar esse
  74.       // modal result na função TFormBlender.ShowMe
  75.       Self.ModalResult := ShowModal;
  76.     finally
  77.       Close;
  78.       Free;
  79.     end;
  80. end;
  81.  
  82. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement