Link to home
Start Free TrialLog in
Avatar of quentin1
quentin1

asked on

AfterShow Event

Does anybody know how can I create an aftershow event for a form?
For eg. i have a function i want to call after the form is showed.
I called it in OnActivate and OnShow events of the that form but in both cases
first is called the function and then is showed the form.
What must I do to call the function after the form is showed?
Avatar of geobul
geobul

Hi,

OnActivate works fine for me:

procedure TForm1.FormActivate(Sender: TObject);
begin
  ShowMessage('Showed');
end;

Regards, Geo
dunno if this works:

const
  WM_AFTERSHOW = WM_USER + 1;

type
  TForm1 = ...
  private
    FOnAfterShow: TNotifyEvent;
  protected
    procedure WMAfterShow(var Msg: TMessage); message WM_AFTERSHOW;
    ...
  public
    property OnAfterShow: TNotifyEvent
      read FOnAfterShow write FOnAfterShow;
  end;

...

procedure TForm1.WMAfterShow(var Msg: TMessage);
begin
  if Assigned(OnAfterShow) then
    OnAfterShow(Self);
end;

procedure TForm1.OnActivate(Sender: TObject);
begin
  PostMessage(Handle, WM_AFTERSHOW, 0, 0);
end;



DragonSlayer.
Depends what you're trying to do.

You might want to override DoShow, or OnVisibleChanging.
ASKER CERTIFIED SOLUTION
Avatar of geobul
geobul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's kind of hacky!
hello quentin1, those events happen before the app is accually shown, A method I have used is the Form's OnPaint, There is NO OnPaint until the Form is accually shown, you will nedd to have a Global  Boolean variable like IsFirst, and in your OnPaint  test for IsFirst and then do whatever you need to do and set IsFirst to False, because the OnPaint Event is fired many times


private
  IsFirst: Boolean;


procedure TForm1.FormCreate(Sender: TObject);
begin
IsFirst := True;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
if IsFirst then
  begin
  IsFirst := False;
  //do whatever
  end;
end;
end;
Avatar of quentin1

ASKER

i think geobul's answer is the fastest way to do what I want.however, thanks too all.