PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
start dialog at startu and have the form drawn prior to the dialog
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
start dialog at startu and have the form drawn prior to the dialog
![]() |
start dialog at startu and have the form drawn prior to the dialog |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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. > > > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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. >> >> >> |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

