473,467 Members | 1,981 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Form not closing

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

Nov 21 '05 #1
7 1294
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
////
Nov 21 '05 #2
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.

Nov 21 '05 #3
Strange,

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

Cor

"N! Xau" <nx**@hotmail.com> schreef in bericht
news:11********************@g49g2000cwa.googlegrou ps.com...
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.

Nov 21 '05 #4

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("secL evel"))
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

Nov 21 '05 #5
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("secL evel"))
me.close
End If
Catch ex As Exception
MsgBox("bLogin_Click: Fill error")
End Try End Sub


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
Nov 21 '05 #6

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

Nov 21 '05 #7
NXau,
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?

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
Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ThunderMusic | last post by:
Hi, I'm trying to have a MSN Messenger like form/app closing behavior. When I click on the X button, I only want the form to disappear and when I double-click on the notify icon or right-click...
5
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
1
by: Chris Bruce | last post by:
In my application I need a way to distiguish between the following events: 1. When a user closes an MDI child window. 2. When the user closes the MDI parent window which subsequently closes the...
2
by: Nenad Dobrilovic | last post by:
Hi, is there any way to find out how form was closed (by calling it's method Close() or by clicking on the 'close' button in control box)? Also, can I close the form in that way that Cloing/Closed...
6
by: Gary Miller | last post by:
Does anyone know how to detect a modeless form on closing by the form that invoked the modeless form? form.Show();
1
by: **Developer** | last post by:
When I get a closing event in a MID Child form I don't know if the child form is closing or the main form is closing. Is there a way to tell? Thank
6
by: **Developer** | last post by:
I've been looking but can't find out how in a form Closing event to know if the closing is because the form's "X" had been clicked or the main form's "X" was clicked. That is, I need to know if...
11
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok /...
19
by: zacks | last post by:
I have a .NET 2.0 MDI application where the child form has a Tab Control. Each of the Tab in the Tab Control has a Validating event to handle what it should do when the user changes tabs. But...
19
by: rbrowning1958 | last post by:
Hello, I am confused by dispose etc. and hope someone can set me right. 1. The Dispose(Bool) the IDE generates for a form has nothing to do with IDisposable, right? 2. So when is this called?...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.