Form not closing

N

N! Xau

Hi all,

I've a problem with a login form that doesn't close. I want it closes
after successful login, calling another form (the application main
form).
I tried with Dispose() and close(), and this way it closes the called
form, too. Without such methods, the login form stays in background,
and once I close the main form,
login form is still on the screen, and doesn't close.
So I added a main module, as follows:

Public Module main
Sub main()
Dim formLogin As New LoginForm
If (formLogin.ShowDialog() = DialogResult.OK) Then
'formLogin.Close() or formLogin.Dispose here
' closes both forms.
Application.Run(New MainForm)
End If
End Sub
End Module


Code into formLogin to call formMain is:

....
Dim formMain As New MainForm
formMain.Owner = Me
formMain.Show()
Me.Enabled = False
....


Thanks for help

N! Xau
 
C

Cor Ligthert [MVP]

N!Xau,

Why don't you start your login form in the load event from your mainform, it
saves you a lot of thinking how to do this?

\\\
Sub load_....................
Dim formLogin As New LoginForm
If formLogin.ShowDialog <> DialogResult.OK Then
me.close
Else
formLogin.dispose
End if
'go on with your loading.
..
End Sub
////
 
N

N! Xau

Cor:
Sub load_....................
Dim formLogin As New LoginForm
If formLogin.ShowDialog <> DialogResult.OK Then
me.close
Else
formLogin.dispose
End if
'go on with your loading.
.
End Sub


This way, each time the login is successful - I don't know why - a new
istance of login form is created.
 
C

Cor Ligthert [MVP]

Strange,

Can you show how you did it.
I assume that you removed that application sub main part

Cor
 
N

N! Xau

Cor Ligthert [MVP] ha scritto:
Strange,

Can you show how you did it.
I assume that you removed that application sub main part


Yes, now it's almost ok.
But still, there's something weird. It needs TWO click on the button to
exit login form and transfer control to the main form. First click has
no effect but to repeat the work. Code is
(button on login form)

Private Sub bLogin_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bLogin.Click
Dim QUsers As String = "select userID, userPass, secLevel from
myTable"
Dim cmdUsers As New OracleCommand(QUsers, con)
Dim adapt As New OracleDataAdapter(cmdUsers)
Dim myDataSet As DataSet = New DataSet("myDataSet")
Try
If adapt.Fill(myDataSet, "tableT") = 0 Then
Me.bLogin.DialogResult = DialogResult.None
MsgBox("User ID or Password not found", MsgBoxStyle.Critical)
Me.txtUserID.Text = ""
Me.txtPass.Text = ""
Else
Me.bLogin.DialogResult = DialogResult.OK
SecurityLevel =
CStr(myDataSet.Tables("tableT").Rows(0).Item("secLevel"))
End If
Catch ex As Exception
MsgBox("bLogin_Click: Fill error")
End Try
End Sub


and code for main form is

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim FormLogin As New Form_Login
If formLogin.ShowDialog <> DialogResult.OK Then
Me.Close()
Else
formLogin.Dispose()
End If
...



TIA

N! Xau
 
C

Cor Ligthert [MVP]

N!Xau,

Can you try it with this

see inline
Private Sub bLogin_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bLogin.Click
Dim QUsers As String = "select userID, userPass, secLevel from
myTable"
Dim cmdUsers As New OracleCommand(QUsers, con)
Dim adapt As New OracleDataAdapter(cmdUsers)
Dim myDataSet As DataSet = New DataSet("myDataSet")
Try
If adapt.Fill(myDataSet, "tableT") = 0 Then

Me.DialogResult = DialogResult.None
MsgBox("User ID or Password not found", MsgBoxStyle.Critical)
Me.txtUserID.Text = ""
Me.txtPass.Text = ""
Else

Me.DialogResult = DialogResult.OK
SecurityLevel =
CStr(myDataSet.Tables("tableT").Rows(0).Item("secLevel"))
me.close

End If
Catch ex As Exception
MsgBox("bLogin_Click: Fill error")
End Try

In my opinion do you have to extend your code a little bit , I would include
a static count and when that is 3 and not well done do me.close

I hope this helps,

Cor
 
N

N! Xau

Cor Ligthert [MVP] ha scritto:

Me.DialogResult = DialogResult.None
[cut]
Me.DialogResult = DialogResult.OK

me.close


Cor, now it works just fine. I did change the 2 me.bLogin.dialogresult
into me.dialogResult.
I did not use me.close cause it's used into main form load code.
Btw, I had to put the rest of this code into the case OK, otherwise it
raises an exception when it exits with dialogresult.Cancel (e.g. when
user closes the login form clicking the window closing button)
I would include
a static count and when that is 3 and not well done do me.close

This, I didn't get. What you mean?


Thanks a lot
N! Xau
 
C

Cor Ligthert [MVP]

NXau,
This, I didn't get. What you mean?
Your user can stop the program now only by a click on the close button.

I think that you can allow him only three times to input the password
username and than stop the program. (That is up to you, however in my
opinion nicer)

Cor
 

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