Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot get logon form to display with focus after splash screen

Status
Not open for further replies.

dalchri

Programmer
Apr 19, 2002
608
US
I have a splash screen that is displayed before my logon form. If I eliminate the splash screen, the logon form is displayed topmost with focus.

However, adding the splash screen leaves logon form hidden behind other windows. Also, the taskbar button that appears for the logon form is blinking and the logon form is grey at the top of the window. The user must click on the form to begin typing.

Code:
[STAThread]
private static void Main() {
Splash frmSplash = new Splash();
frmSplash.Show();

//Haven't I tried everything I can to get this out
//of memory?
frmSplash.Close();
frmSplash.Dispose();
frmSplash = null;
GC.Collect();

Logon frmLogon = new Logon();
//Logon form is not focused by the following
Application.Run(frmLogon);
}

I have also found that putting this.Activate, this.Focus, this.BringToFront, in the Load event for the Logon form are all ineffective.

It seems like I can't get .NET to forget whatever displaying the splash form did to the application state.

Thank you for any suggestions!
 
This does not work either:

frmLogon.ShowDialog();

-in place of-

Application.Run(frmLogon);

I really don't understand why showing my splash form first is causing this.
 
Why does your application just run the logon form. Surely after logging on, you will start the application proper.

So what I meant was:

After the splash screen has closed, open the logon form as a dialog and then use Application.Run to open your program's main form.


 
I omitted the rest of my code to keep the example concise. After the logon form is completed, the program's main form is displayed:

MainForm frmMain = new MainForm();
Application.Run(frmMain);
 
Are you saying that after closing the splash screen:

Logon frmLogon = new Logon();
frmLogon.ShowDialog();
MainForm frmMain = new MainForm();
Application.Run(frmMain);

doesn't open the logon form topmost and then your main form after you close the logon form?
 
The logon form does open but not topmost. Once the logon form is closed, the main form opens ok.

Something else that is a little screwy is that everything is fine from the IDE when pushing the "play" button to start the program. The problem only occurs when you launch from the exe or a shortcut to the exe.

Thanks again for looking to this!
 
This appears to be the trick:

Code:
[STAThread]
private static void Main() {
Splash frmSplash = new Splash();
frmSplash.Show();

//Create, show, and activate the logon form before
//hiding the splash form
Logon frmLogon = new Logon();
frmLogon.Show();
frmLogon.Activate();
frmSplash.Close();

Application.Run(frmLogon);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top