tags:

views:

46

answers:

3

I am using Visual Basic 2010 and I am makeing a simple login app it prompts you for a username and password if it gets it right I want to open a form then close the previus one but when I do me.close it ends the program and I can't go on

I am positive its working because I get the right password and username ut I can't close the first windows

I tried to hide it but when I do I cant close it and the program goes on without quiting and with a hidden form

I heard rumers that there is Sub that can control the x in the corner

if there is one that would probably solve my problem but I can't find it heres the code for the login form

Public Class Main_Login
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "My Name" And TextBox2.Text = "mypassword" Then
            Contentsish.Show()
            Me.Hide()
            Label3.Hide()
        Else
            Label3.Show()
        End If
    End Sub
End Class

Then the Form if you enter the right login info

Public Class Contentsish
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Hide()
        Timer1.Stop()
    End Sub
End Class

how can I fix this problem?

+1  A: 

Go into your project settings and set the application to close when the last form closes and not when the startup form closes.

edit: I just checked some of my VB.Net 2k8 code. What I do is create a new instance of the "child" form, do any initialization that I need, call .Show() on it, and then call .Close() on the current form (Me.Close()). Probably not the best way to do things, but it works for me. This is with the project setting I described earlier set. This allows me to exit from the child form or "logout" if needed.

Crag
it worked thanks
Luck
@Luck -- if @Crag's answer was correct, it is good etiquette to check the green checkmark for his answer. This way, we know the question was successfully solved.
LittleBobbyTables
got it its done
Luck
sorry I am new I didn't know
Luck
A: 

Two other ways you can do this, in addition to Crags:

  1. Load the main form first, then load the password from the main form.

  2. You can use a separate vb module and use the Sub Main for the startup (you specify this in Project Properties, Application, Startup Object), then load the two forms from Sub Main.

xpda
A: 

So what happens if the login is incorrect? Sounds like you might want to show the login form using ShowDialog, maybe in your Main() before calling Application.Run(new FormMain());

Jason Goemaat
if the login is incorrect I have a label appear that says the username or password is incorrect in red :)
Luck