start dialog at startu and have the form drawn prior to the dialog

G

Guest

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.
 
S

Stoitcho Goutsev \(100\) [C# MVP]

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);
}
 
G

Guest

The 2nd solution does the job just fine - Thanx!!!

Hans.

Stoitcho Goutsev (100) said:
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.
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hans,
I know that you had this issue resolved, but just for the record I want to
share my dicovery.
I said before that Micrsoft never had clear indication of when the form is
drawn and shwon on the screen. I just found that they've added this to .NET
2.0 windows forms. The event is called Form.Shown and the way they have
implemented it is the same as my second suggestion - using
Control.BeginInvoke.


--

Stoitcho Goutsev (100) [C# MVP]

Hans said:
The 2nd solution does the job just fine - Thanx!!!

Hans.

Stoitcho Goutsev (100) said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top