15 don\'t show the form\"." />
开发者

Delphi: is it possibile in the OnFormShow event to tell a form not to display even for a millisecond?

开发者 https://www.devze.com 2023-03-30 00:22 出处:网络
In the OnFormShow event I need (for a particular set of conditions) not to show the form. Something like \"if counter > 15 don\'t show the form\".

In the OnFormShow event I need (for a particular set of conditions) not to show the form.

Something like "if counter > 15 don't show the form".

I could of course refactor and move many things on form create, but this is a lot of work, because this is a common form and there are too many changes involved.

Now I close the form at the end of OnFormShow but anyway I see the form appear for some millisecond开发者_C百科s.

Unfortunately the condition that tells me not to show the form is decided inside OnFormShow. Is there a trick to avoid the form to show?


Refactor your code so that it doesn't show at all until you are ready. Either refrain from calling Show, or set Visible to False if you have not yet done so.

I suspect it's too late by the time you reach OnShow but even so doing it that way would be indicative of poor design. Moving code out of OnShow into a different method really should not be very much trouble at all.


+1 on the refactoring, but in the mean time, try this:

AlphaBlend := true;

AlphaBlendValue := 0;

That should make the form invisible, and seemed to work in my OnShow test app (D2010/XP). I'm guessing you'll need to add code to make the form close, possibly a timer?


A very bad solution is to do

procedure TForm1.FormShow(Sender: TObject);
begin
  inc(n);
  if n > 15 then
  begin
    Left := Screen.DesktopWidth + 32;
    Top := Screen.DesktopHeight + 32;
    PostMessage(Handle, WM_CLOSE, 0, 0);
  end;
end;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号