Close form...

  • Thread starter Thread starter Fabio Negri Cicotti
  • Start date Start date
F

Fabio Negri Cicotti

Hi.

Imagine a scene where the user input the username and password in a "Login"
form and when press the confirm button, another window is opened with the
"Main" form. After that, the "Login" form is "closed" automatically.

How can I do to close the "Login" form? If I use Login.Close() on the
button_click event, both forms are closed.


Thanks a lot.

Fabio Negri Cicotti
 
Fabio,

I would just run two message loops. The code that VS.NET produces for
you looks like this:

// Run the message loop with a form.
Application.Run(new Form1());

There is nothing that stops you from doing this:

// The login form.
LoginForm pobjLoginForm = new LoginForm();

// Show the login form.
Application.Run(pobjLoginForm);

// Apply some logic here, based on the properties of the form, like if the
user succeeded in logging in or not.

// Run the main form here.
Application.Run(new MainForm());

Hope this helps.
 
Thanks for your reply Nicholas.

I have tried to do what you said, but I didn't get successful. I'm taking
the follow error message:

"Additional information: It is invalid to start a second message loop on a
single thread. Use Application.RunDialog or Form.ShowDialog instead."


Any help is appreciated,

Fabio Negri Cicotti



Nicholas Paldino said:
Fabio,

I would just run two message loops. The code that VS.NET produces for
you looks like this:

// Run the message loop with a form.
Application.Run(new Form1());

There is nothing that stops you from doing this:

// The login form.
LoginForm pobjLoginForm = new LoginForm();

// Show the login form.
Application.Run(pobjLoginForm);

// Apply some logic here, based on the properties of the form, like if the
user succeeded in logging in or not.

// Run the main form here.
Application.Run(new MainForm());

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Fabio Negri Cicotti said:
Hi.

Imagine a scene where the user input the username and password in a "Login"
form and when press the confirm button, another window is opened with the
"Main" form. After that, the "Login" form is "closed" automatically.

How can I do to close the "Login" form? If I use Login.Close() on the
button_click event, both forms are closed.


Thanks a lot.

Fabio Negri Cicotti
 
Hi, Fabio

that's exactly what you need - ShowDialog for login form.
What stops you to use it before doing Application.Run for main form?

HTH
Alex

Fabio Negri Cicotti said:
Thanks for your reply Nicholas.

I have tried to do what you said, but I didn't get successful. I'm taking
the follow error message:

"Additional information: It is invalid to start a second message loop on a
single thread. Use Application.RunDialog or Form.ShowDialog instead."


Any help is appreciated,

Fabio Negri Cicotti



message news:[email protected]...
Fabio,

I would just run two message loops. The code that VS.NET produces for
you looks like this:

// Run the message loop with a form.
Application.Run(new Form1());

There is nothing that stops you from doing this:

// The login form.
LoginForm pobjLoginForm = new LoginForm();

// Show the login form.
Application.Run(pobjLoginForm);

// Apply some logic here, based on the properties of the form, like if the
user succeeded in logging in or not.

// Run the main form here.
Application.Run(new MainForm());

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Fabio Negri Cicotti said:
Hi.

Imagine a scene where the user input the username and password in a "Login"
form and when press the confirm button, another window is opened with the
"Main" form. After that, the "Login" form is "closed" automatically.

How can I do to close the "Login" form? If I use Login.Close() on the
button_click event, both forms are closed.


Thanks a lot.

Fabio Negri Cicotti
 
Fabio,

Interesting, what version of the framework are you running on? I am on
1.1, and it doesn't prevent me from doing this.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Fabio Negri Cicotti said:
Thanks for your reply Nicholas.

I have tried to do what you said, but I didn't get successful. I'm taking
the follow error message:

"Additional information: It is invalid to start a second message loop on a
single thread. Use Application.RunDialog or Form.ShowDialog instead."


Any help is appreciated,

Fabio Negri Cicotti



message news:[email protected]...
Fabio,

I would just run two message loops. The code that VS.NET produces for
you looks like this:

// Run the message loop with a form.
Application.Run(new Form1());

There is nothing that stops you from doing this:

// The login form.
LoginForm pobjLoginForm = new LoginForm();

// Show the login form.
Application.Run(pobjLoginForm);

// Apply some logic here, based on the properties of the form, like if the
user succeeded in logging in or not.

// Run the main form here.
Application.Run(new MainForm());

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Fabio Negri Cicotti said:
Hi.

Imagine a scene where the user input the username and password in a "Login"
form and when press the confirm button, another window is opened with the
"Main" form. After that, the "Login" form is "closed" automatically.

How can I do to close the "Login" form? If I use Login.Close() on the
button_click event, both forms are closed.


Thanks a lot.

Fabio Negri Cicotti
 

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