calling a form from a form

G

Guest

hi ! i've recently begun developing in c# and i'd like to know what's the
best way of calling a form from an already instanced form ? I have done a
"Login" form which I run in the Main() using "Application.Run(...)", now when
the user logins correctly, another form named "Calendar" must be called. How
can I do this ? Should I close the first form first and then instance the
new one or how ? Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

Renzo,

My preference is to have two application loops, like so:

// Show the login form.
Application.Run(new LoginForm());

// Show the Calendar form.
Application.Run(new CalendarForm());

If you need access to the variables, you could do something like:

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

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

// The calendar form. Initialize with login form to get access to it.
CalendarForm cf = new CalendarForm(lf);

// Show the form.
Application.Run(cf);

Hope this helps.
 
G

Guest

Thanks Nicholas. I will do it that way too. Currently, I was calling it
from the frmLogin using ShowDialog() but this means that the previous form is
still loaded. I was using Hide() to make it dissappear but I feel it was not
the correct way. I prefer your method.

Cheers.



Nicholas Paldino said:
Renzo,

My preference is to have two application loops, like so:

// Show the login form.
Application.Run(new LoginForm());

// Show the Calendar form.
Application.Run(new CalendarForm());

If you need access to the variables, you could do something like:

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

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

// The calendar form. Initialize with login form to get access to it.
CalendarForm cf = new CalendarForm(lf);

// Show the form.
Application.Run(cf);

Hope this helps.


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

Renzo said:
hi ! i've recently begun developing in c# and i'd like to know what's the
best way of calling a form from an already instanced form ? I have done a
"Login" form which I run in the Main() using "Application.Run(...)", now
when
the user logins correctly, another form named "Calendar" must be called.
How
can I do this ? Should I close the first form first and then instance the
new one or how ? Thanks.
 

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