Trouble opening one form and closing or hiding the calling form

D

David Hearn

I am having a problem trying to close or hide (have tried it both
ways) one form and showing another. The initial form is a login form.
If they get the username and password correct, I want it to go to
frmMain and close the login screen since it won't be needed anymore.
If I try either one, the application gets lost somewhere. I can go
into running apps and see that the application is still there and
eventually find it but it is like it is getting hidden behind the
desktop. What am I doing wrong?

Here is the code I am using:

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLogin.Click
If txtUserName.Text.Length = 0 Then
MessageBox.Show("UserName Required!")
Exit Sub
ElseIf txtPassword.Text.Length = 0 Then
MessageBox.Show("Password Required!")
Exit Sub
End If
Dim objMain As New frmMain
objMain.Show()
objMain.Focus()
Me.Close() 'I have tried Me.Hide[] here also
End Sub
 
D

David Hearn

Updated information:

me.close is shutting down application. Now that I had a chance to
watch it closer, I noticed that it is shutting down the application.
What is going on?
 
A

Alex Feinman

The application run-time cycle rotates around a mian
form - the one that was specified as an argument to the
Application.Run(). In your scenario you are trying to
create (another?) instance of the frmMain dynamically. It
does not work like that.

I suggest that you create your Login dialog from the main
form and display it using ShowDialog. Upon returniong
from ShowDialog you can validate password and user name
in the main form and if it does not match, pop up the
login dialog again
 
D

David Hearn

Thanks Alex. I didn't know that it all rotated around that form. I
have it working now.


The application run-time cycle rotates around a mian
form - the one that was specified as an argument to the
Application.Run(). In your scenario you are trying to
create (another?) instance of the frmMain dynamically. It
does not work like that.

I suggest that you create your Login dialog from the main
form and display it using ShowDialog. Upon returniong
from ShowDialog you can validate password and user name
in the main form and if it does not match, pop up the
login dialog again
-----Original Message-----
I am having a problem trying to close or hide (have tried it both
ways) one form and showing another. The initial form is a login form.
If they get the username and password correct, I want it to go to
frmMain and close the login screen since it won't be needed anymore.
If I try either one, the application gets lost somewhere. I can go
into running apps and see that the application is still there and
eventually find it but it is like it is getting hidden behind the
desktop. What am I doing wrong?

Here is the code I am using:

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLogin.Click
If txtUserName.Text.Length = 0 Then
MessageBox.Show("UserName Required!")
Exit Sub
ElseIf txtPassword.Text.Length = 0 Then
MessageBox.Show("Password Required!")
Exit Sub
End If
Dim objMain As New frmMain
objMain.Show()
objMain.Focus()
Me.Close() 'I have tried Me.Hide[] here also
End Sub
.
 

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