0

I have a Splash Screen to my program.

And when the splash end , exec the code

this.Hide();
frmLogin o = new frmLogin();
o.show();

And it works but the splash screen go invisible and when i close the program by my custom exit button it's only closing the current form. But my splash screen is still hidden and appears the app name to task manager. How i can close that currently opened form and the invisible ones with my custom button ?

Sebi
  • 3,879
  • 2
  • 35
  • 62
  • 1
    Use `Close()` instead of `Hide()`. – dymanoid Nov 11 '16 at 14:47
  • search how to use [Application.OpenForms](https://msdn.microsoft.com/en-us/library/system.windows.forms.application.openforms%28v=vs.110%29.aspx) – Steve Nov 11 '16 at 14:48
  • i tried but it closes the both froms. –  Nov 11 '16 at 14:48
  • Just don't hide it and you don't have a problem. That probably makes your app terminate, [that is easy to fix](http://stackoverflow.com/a/10769349/17034). Or simply don't make your splash screen or your login window the main window. – Hans Passant Nov 11 '16 at 14:53

2 Answers2

1

You are launching your whole application from the splash screen form.

It would be better avoid this behaviour separating splash screen form from main form, and opening up from this last form the splash screen, as well as you have done with frmLogin.

However you can workaround this problem using this.Hide() and at the exit of the program using Application.Exit() within your "custom exit button" event.

Ciro Corvino
  • 2,038
  • 5
  • 20
  • 33
1

While in design view, select the frmLogin button. On the right, the Properties window should update. Select the Events tab. Look for FormClosing in the list of events. Select the right column and type a method name of your choice. If you typed xBtnPress, the designer will generate a stub that will look like this:

private void xBtnPress(object sender, FormClosingEventArgs e) {

}

If you wish to close your application upon this event, call Application.Exit() from within the event handler.

wp78de
  • 18,207
  • 7
  • 43
  • 71
herahadi
  • 11
  • 4