What is the recommended way to ensure that the mainform is fully maximized and all controls are redrawn before showing a modal form on application first load?
I need to show a modal dialog when the application starts (not a login screen) but if I set the form to wsMaximized
whilst the screen maximizes, the controls do not have chance to redraw and you are left with an ugly mess.
I show the modal screen at present using the following:
procedure TForm1.FormActivate(Sender: TObject);
var
frmOrderLookup:TfrmOrderLookup;
begin
onactivate := nil;
frmOrderLookup:=TfrmOrderLookup.Create(nil);
try
frmOrderLookup.showmodal;
finally
frmOrderLookup.Free;
end;
end;
What I normally do is post a custom message back to my form. That way it won't get processed until other messages for the form have already been handled. By the time this message gets processed, your form should have already finished redrawing.
type
TMyForm = class(TForm)
procedure FormCreate(Sender: TObject);
private
procedure HandleLookupMessage(var Message: TMessage); message WM_USER + 1;
end;
procedure TMyForm.HandleLookupMessage(var Message: TMessage);
var
frmOrderLookup: TfrmOrderLookup;
begin
frmOrderLookup := TfrmOrderLookup.Create(Application);
try
frmOrderLookup.ShowModal;
finally
frmOrderLookup.Release;
end;
end;
procedure TMyForm.FormCreate(Sender: TObject);
begin
// Maximise form here if needed
PostMessage(Handle, WM_USER + 1, 0, 0);
end;
If you're worried about the message getting to your application again somehow, you can always add a private boolean variable to indicate that it's been handled once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With