Help with multiple Forms in vb.net

  • Thread starter Thread starter Diederick Kruger
  • Start date Start date
D

Diederick Kruger

I want to call a form from an existing form

Ex:

1. My first form is my login form.
2. Now I want to call the main form when the user clicks on the LOG IN
button.

How do I do this?

Thanx Diederick
 
The languages we use to develop to .NET CF are object oriented, so (quite)
everything is an object, even forms. As such, prior to use a form, you have
to declare it on a variable and instantiate it. You interact with the form
thru the variable you have declared, which has some implications:
- if you need you may have more than one instance of the form
- you have to be careful with the scope of the variable where you instantiate
the form, specially if you need to keep a reference to a particular instance.

Sample code?

On frmLogin, you need (vb.net) ...

Dim myFormMain as new frmMain

myFormMain.Show

If you need to refer to that instance of the main form, which will happen
each time you get back from the other forms you'll create, you may need to
declare the myFormMain variable with a 'global' scope.

This is only the beginning of dealing with multiform applications...

Alberto Silva
MS Mobile Devices MVP
http://msmvps.com/AlbertoSilva
 
This is not a CF-specific question but...

Dim f As New frmMain()
f.Show()

However, I'd suggest you make your main form the startup form and show from
there the login form (forbidding access to the main form unless the login
process is successful).

Alternatively, place the login controls in a panel. Have that panel cover
your main form. When the login process is successful, hide the panel and
reveal your main form controls.

Cheers
Daniel
 
Back
Top