Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to vb.net, need to close a form... 5

Status
Not open for further replies.

IanNav

Programmer
Feb 26, 2001
79
Hi,

I am new to vb.net (but have been using vb6 for a while), and i am trying to do something extremly simple.

But it is frustrating me...!

Basically i have 2 forms.

1) Loginfrm
2) Userfrm

I load the login form, and when i press ok on it i want it to close the login form and open the user form.

In vb6 i would use the unload() function, but i can't seem to get the hang of doing it in .net.

I try to use the .close function on the form object but it closes the whole project... which is not what i want.

Can anyone explain how to do this real simple task and where i am going wrong.

Thanks

Ian

 
This should give you a start:
Code:
Dim frmSwitchBoard As New frmSwitchBoard
Me.Hide()
frmSwitchBoard.ShowDialog()

DO NOT use Me.Dispose(), I learned the hard way.

Good Luck
djj

 
The .close should work just fine for you. You say that it closes the entire application. Is it possible it's the only form open at the time, or the startup object of the solution? Also, you can optionally use .hide, but this doesn't destroy the object or allow garbage collection to destroy it either.
 
Doesn't hide just hide the form though.

I don't want to have it still loaded into memory. how do i unload it.

What .dispose() do..? sounds dangerous :)

Thanks for the post djj55
 
SavantMan,

When i step through the code, it gets to the .close and closes the login form...

Then when it steps past the end sub of that piece of code it closes the whole application.

I don't really want to use .hide.

What am i doing wrong, why it it so confusing compared to vb6?

Thanks
 
The reason why the app closes, is by default, applications are set to exit when the start-up form closes. There is a setting in the applications configuration file that can be changed to application exit on all forms closed.

Barring that change, you could also use your main form as the applications start up form, but hide it as soon as it loads. Then show the login form as a dialog, which will close the form automatically when the user hits ok or cancel. On the closing event of the login form, unhide the main form
 
Caoamo,

That explains everything.

Thank you very much....

i dont' know how im gonna get on with .net it seems to be 1 step fwd 3 steps back...!

I'll keep at it.

Thanks everyone for the help.

Cheers
 
Don't get discouraged IanNav --- it's not an easy switch to make. It's a bit daunting at first, but after you've worked in .Net for a bit, the payoff will be well worth it.
 
Will do SavantMan,

I aint beaten yet...

It just makes me think if i have trouble doing something simple. how on earth am i gonna be able to do anything complicated!

anyway. i'll keep bothering this board with questions when i get stuck.

Cheers

 
Dispose does the same thing close does with exiting the application.
Caoamo - Thanks for the info.
djj
 
You could start your program with something like in a Module (sorry chrissie [wink]):

Typed not tested

Code:
Public LogOnOK as Boolean = False

Public Sub Main()
Dim frmUserForm as New UserForm
Dim frmLogOnForm as New LogOnForm
  frmLogon.ShowDialog()
  frmLogOn = Nothing
  'The log on form sets LogOnOK to True if log on is ok
  If LogOnOK Then
    Application.Run(frmUserForm)
  End If

End Sub

Using this method:

The logon form will be displayed as a dialog box - if the user is validated the logon form will set the global variable LogOnOK to true.

If logon is successful, the user form will be displayed and the program will run until the user form is closed.

If logon is unsuccessful, the program will terminated as soon as the logon form is closed.


Hope this helps.

[vampire][bat]
 
If you want the app not to end, then dont' just write 'me.dispose()', but 'me.dispose(false)'
 
Thanks for everyone's help.

Earthand fire - nice method, thanks.

TipGiver - Useful false on dispose.

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top