Design question for forms

D

Dan Reber

I have an application that does not transition well between two forms. When
the user starts the app my login form opens, after they login the main form
then opens but there is a few seconds lag between when the login form closes
and the main form opens. Is there a different ways to do this and still have
my login form open first? Below is my Program.cuss code.

frmLogin form = new frmLogin();
Application.Run(form);

if (form .DialogResult == DialogResult.OK)
Application.Run(new frmMain(form.AppConnection));

Also, I have some dialogs that after they are closed a potion of the form is
still painted on the screen while some code is executed based on the
selection in the dialog. Is there a way to make sure that the code that is
executed after the close of the dialog does not start until after the dialog
forms have be completely removed from the screen?

Thanks

Dan
 
C

Chris Dunaway

I have an application that does not transition well between two forms. When
the user starts the app my login form opens, after they login the main form
then opens but there is a few seconds lag between when the login form closes
and the main form opens. Is there a different ways to do this and still have
my login form open first? Below is my Program.cuss code.

frmLogin form = new frmLogin();
Application.Run(form);

if (form .DialogResult == DialogResult.OK)
Application.Run(new frmMain(form.AppConnection));

Also, I have some dialogs that after they are closed a potion of the form is
still painted on the screen while some code is executed based on the
selection in the dialog. Is there a way to make sure that the code that is
executed after the close of the dialog does not start until after the dialog
forms have be completely removed from the screen?

One thing is that there is no need to call Application.Run twice.
Perhaps something like this will help:

using (frmLogin form = new frmLogin()) {
if (form.ShowDialog() == DialogResult.OK)
Application.Run(new frmMain(form.AppConnection));
}

Use the using keyword to make sure the login form is disposed.

Don't know if this will solve your transition problem, but it might
help.

Chris
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


Dan Reber said:
I have an application that does not transition well between two forms.
When the user starts the app my login form opens, after they login the main
form then opens but there is a few seconds lag between when the login form
closes and the main form opens. Is there a different ways to do this and
still have my login form open first? Below is my Program.cuss code.

frmLogin form = new frmLogin();
Application.Run(form);

if (form .DialogResult == DialogResult.OK)
Application.Run(new frmMain(form.AppConnection));

Why are you creating the form like that?

DO instead
if (form .DialogResult == DialogResult.OK)
new frmMain(form.AppConnection).Show();
 
D

Dan Reber

I changed the code to

using (frmLogin loginForm = new frmLogin())
if (loginForm.ShowDialog() == DialogResult.OK)
Application.Run(new frmMain(loginForm.AppConnection));

it does not fix the transition issue but it makes more sense this way.

Thanks

Dan
 
D

Dan Reber

Looks like I did not need to call Application.Run to open the dialog but
don't I need to use it to open my main form? I tried your code and the form
just opened and closed right away.

Thanks

Dan
 
G

Guest

Apply the mvc pattern, use an event sync the closing process and a controller
which will listen to the evetn and apply the code.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Dan Reber said:
Looks like I did not need to call Application.Run to open the dialog but
don't I need to use it to open my main form? I tried your code and the
form just opened and closed right away.

You only need to call Application.Run once in your program, to create the
first form. Take a look at MSDN for a detailed explanation of what it does,
basically it create a message pump that allows your forms to receive events.
 
D

Dan Reber

OK, thanks for your help.

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,



You only need to call Application.Run once in your program, to create the
first form. Take a look at MSDN for a detailed explanation of what it
does, basically it create a message pump that allows your forms to receive
events.
 

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

Top