PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Forms start dialog at startu and have the form drawn prior to the dialog

Reply

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

 
Thread Tools Rate Thread
Old 14-12-2005, 12:19 PM   #1
=?Utf-8?B?SGFucw==?=
Guest
 
Posts: n/a
Default start dialog at startu and have the form drawn prior to the dialog


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.
  Reply With Quote
Old 14-12-2005, 02:35 PM   #2
Stoitcho Goutsev \(100\) [C# MVP]
Guest
 
Posts: n/a
Default Re: start dialog at startu and have the form drawn prior to the dialog

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" <Hans@discussions.microsoft.com> wrote in message
news:E313E940-CB34-49B7-AE7F-18F58A59B480@microsoft.com...
> 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.



  Reply With Quote
Old 15-12-2005, 07:25 AM   #3
=?Utf-8?B?SGFucw==?=
Guest
 
Posts: n/a
Default Re: start dialog at startu and have the form drawn prior to the di

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

Hans.

"Stoitcho Goutsev (100) [C# MVP]" wrote:

> 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" <Hans@discussions.microsoft.com> wrote in message
> news:E313E940-CB34-49B7-AE7F-18F58A59B480@microsoft.com...
> > 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.

>
>
>

  Reply With Quote
Old 20-12-2005, 08:12 PM   #4
Stoitcho Goutsev \(100\) [C# MVP]
Guest
 
Posts: n/a
Default Re: start dialog at startu and have the form drawn prior to the di

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" <Hans@discussions.microsoft.com> wrote in message
news:2077378F-E544-4460-B565-4185575C5048@microsoft.com...
> The 2nd solution does the job just fine - Thanx!!!
>
> Hans.
>
> "Stoitcho Goutsev (100) [C# MVP]" wrote:
>
>> 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" <Hans@discussions.microsoft.com> wrote in message
>> news:E313E940-CB34-49B7-AE7F-18F58A59B480@microsoft.com...
>> > 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.

>>
>>
>>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off