Hans,
Windows has never had clear indicaton of when a window has been fully
created and drawn on the screen. There were always been workarounds though.
1. The oldest is to start a timer (System.Windows.Forms.Timer) in the form
constructor for some really small time interval (1 ms) since the WM_TIMER
message one of the lowest priority messages the event handler of the timer
will come only after all the messages in the message queue are processed -
means that the form (window) will be fully created and shown on the screen.
If you prefer this workaround don't forget to stop the timer when you
reveive the Tick event.
2. This one looks more natural and I'd recomend it.
Override form's OnLoad method. When this method comes the form object and
its underlying window handler are clreated, but the form hasn't been drawn
yet.
In OnLoad call the method that will show the dialog box, but call it using
Control.BeginInvoke method. This will schedule the methods call for later.
This way the dialog displaying method will be call after the form is
displayed. Something like this:
protected override void OnLoad(EventArgs e)
{
this.BeginInvoke(new MethodInvoker(DoShowDialog));
base.OnLoad (e);
}
void DoShowDialog()
{
Form2 f2 = new Form2();
f2.ShowDialog(this);
}
--
HTH
Stoitcho Goutsev (100) [C# MVP]
Hans said:
My application accepts command line parameters to start specific dialogs
at
application startup. When, however, I issue miStartMyDialog.PreformClick()
in
the constructor or in the load event of the main form, this dialog is
drawn
BEFORE the main form is shown.
How can I make the app look like the dialog was started by pressing the
apprapriate toolbar button (i.e. first draw the main form, then draw the
dialog)?
Thanx for any help,
Hans.