Jump to content
Sign in to follow this  
Guest

my sample How to create a DIMmed effect for your forms -- house-maded

Recommended Posts

Guest

hello friends,

 

here my house-maded to create a "dimmed" effect on your forms...

  • it is not advisable to do this without an adult around .... :classic_biggrin::classic_biggrin::classic_biggrin::classic_biggrin: 😂 :classic_cheerleader:

 

Form Main

Quote

unit uFormMain;

interface
...
type
  TfrmFormMain = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
  public
  end;

var
  frmFormMain: TfrmFormMain;

implementation

{$R *.dfm}

uses
  uFormSecond;

procedure TfrmFormMain.Button1Click(Sender: TObject);
begin
  frmSecondForm.ShowModal;
end;

procedure TfrmFormMain.FormCreate(Sender: TObject);
begin
  Self.Top  := 100;
  Self.Left := (Screen.Width div 2) - (Self.Width div 2);
  //
  frmSecondForm := TfrmSecondForm .Create(nil);
end;

procedure TfrmFormMain.FormDestroy(Sender: TObject);
begin
  FreeAndNil(frmSecondForm);
end;

initialization

ReportMemoryLeaksOnShutdown := true;

finalization

end.

 

 

Form Second -> where the effect will be showed

Quote

unit uFormSecond;

interface
...
type
  TfrmSecondForm = class(TForm)
    StringGrid1: TStringGrid;
    Panel1: TPanel;
    btn_DimIt: TButton;
    btn_UnDimIt: TButton;
    Timer1: TTimer;
    Button1: TButton;
    procedure btn_DimItClick(Sender: TObject);
    procedure btn_UnDimItClick(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    procedure prcWhatIDoWithAllScreenDimmed;
  public
  end;

var
  frmSecondForm: TfrmSecondForm;

implementation

{$R *.dfm}

uses
  uFormToGrayEffect;

var
  lMyOpacityMax : integer = 150; // 0..255 max!!!
  lMyOpacityInit: integer = 0;

procedure TfrmSecondForm.prcWhatIDoWithAllScreenDimmed;
begin
	// what I do here...
end;

procedure TfrmSecondForm.FormCreate(Sender: TObject);
begin
  Timer1.Enabled  := false;
  Timer1.Interval := 1000 div 25; // 25Hz fresh rate...
  //
  Self.Position := TPosition.poScreenCenter;
end;

procedure TfrmSecondForm.FormDestroy(Sender: TObject);
begin
  FreeAndNil(frmFormToGrayEffect);
end;

procedure TfrmSecondForm.btn_DimItClick(Sender: TObject);
begin
  lMyOpacityMax  := 150;
  lMyOpacityInit := 0;
  //
  frmFormToGrayEffect        := TfrmFormToGrayEffect.Create(nil);
  frmFormToGrayEffect.Parent := Self; // the magic start here...
  //
  Timer1.Enabled  := true;
  //
  ShowMessage('Hello Word! Come soon I''ll be back...');
  //
  btn_UnDimIt.Click;
end;

procedure TfrmSecondForm.btn_UnDimItClick(Sender: TObject);
begin
  Self.AlphaBlendValue := 255;
  Self.AlphaBlend      := false;
  //
  FreeAndNil(frmFormToGrayEffect); // because the form exist yet...
end;

procedure TfrmSecondForm.Button1Click(Sender: TObject);
var
  i: integer;
begin
  for i := 0 to (Screen.FormCount - 1) do
  begin
    if Screen.Forms[i].Name = 'frmFormToGrayEffect' then
      ShowMessage('frmFormToGrayEffect live yet...')
    else
      ShowMessage('frmFormToGrayEffect was destroyed...');
  end;
end;

procedure TfrmSecondForm.Timer1Timer(Sender: TObject);
begin
  Inc(lMyOpacityInit, 5);
  //
  if not(frmFormToGrayEffect.Showing) then
    frmFormToGrayEffect.Show;
  //
  frmFormToGrayEffect.AlphaBlendValue := lMyOpacityInit;
  //
  if (lMyOpacityInit >= lMyOpacityMax) then
  begin
    Timer1.Enabled := false;
    //
    prcWhatIDoWithAllScreenDimmed;
  end;
end;

end.

 

Form Third

  • in fact, you dont need the any TImage or anyother component here
  • just use a COLOR like "clGray" in your Form3.Color  you see?
Quote

unit uFormToGrayEffect;

interface
...
type
  TfrmFormToGrayEffect = class(TForm)
    Image1: TImage;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
  public
  end;

var
  frmFormToGrayEffect: TfrmFormToGrayEffect;

implementation

{$R *.dfm}

uses
  uFormSecond;

procedure TfrmFormToGrayEffect.FormCreate(Sender: TObject);
begin
  Self.AlphaBlendValue := 0;
  Self.AlphaBlend      := true;
end;

procedure TfrmFormToGrayEffect.FormShow(Sender: TObject);
begin
  frmFormToGrayEffect.Align := TAlign.alClient;
end;

end.

 

 

image.thumb.png.166db6bff6d80216762906335c32033c.png

 

NOTE: of course, you can use MSWindows API for this effect... but I dont have time for test now... sorry!!!

 

enjoy yourself

 

hug

Edited by Guest

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×