Hide Login screen when entering application

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am new to .Net and Visual Studio, I have a login form and my main
application form. When I login I want to call the application form, and
dispose of the login. I have tried doing something like:

This.Hide
myAppfrm.Show();

but then when I close down the myAppfrm, the system hangs as the login
screen is still floating about in memory. How is this delt with normally in
the .Net fraternity?

Thanks
 
I have done this now, which seems to do the job but not sure how right it is:

if(loggedIn == true)
{
MainScreen myMainScreen = new MainScreen();
this.Hide();
myMainScreen.ShowDialog();
this.dispose();
}

so now it runs the application, then disposes the hidden login screen when
they close the application. Is this correct?
 
You will need to create a Sub Main() Method within a module and set
the Main() method as the startup object, this can be done in the
project properties dialog

the module containing the Sub Main() method will then need to contain
something similar to the following

Module modMain

Public Sub Main()

Dim objLoginForm as New LoginForm

'Use showdialog() instead of show() to stop the
'application from displaying the main form until the
login form has been closed
objLoginForm.ShowDialog

'Create the main form
Dim myAppfrm as new YourMainForm

'Use Application.Run instead of myAppfrm.show as this
will then treat the myAppfrm as the main message loop and not exit the
application until it has closed
Application.Run(myAppfrm)

End Sub

End Module

I hope this helps.

Regards

James Thresher
 
Hi,

Just noticed that you are using c#, my previous post was a solution
for VB.NET, my apologies. the following should work for c#


[STAThread]
static void Main()
{

LoginForm objLoginForm = new LoginForm();

//Use showdialog() instead of show() to stop the
//application from displaying the main form until the
login form has been closed
objLoginForm.ShowDialog();

//Create the main form
YourMainForm myAppfrm = new YourMainForm();

//Use Application.Run instead of myAppfrm.show as this
will then treat the myAppfrm as the main message loop and not exit the
application until it has closed
Application.Run(myAppfrm());

}

Regards

James Thresher
 

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

Back
Top