Close form from another

cuisancio

Member
Joined
Mar 7, 2006
Messages
11
Programming Experience
Beginner
Hello, I had a Vb6.0 app which showed a main form. This form showed another form to login. When you clicked the "Cancel" Button in the login form, this form closed itself and the main form.

Private Sub b_Cancel_Click()

Unload f_Login
Unload f_Main

End Sub

Now, I have to do this app with VB.net and it seems that the "Unload" method doesn't work.

I tried

Private Sub b_cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b_cancel.Click

Me.Close()
f_Main.ActiveForm().Close()

End Sub

But it only closes the "Login form".

Please, how can i close the "f_Main form" in vb.net from the "f_Login" form????
 
Well, I've been reading other post here and i've done some changes in my code:

1.In a Module I've put this:

Module f_Main
Friend Mform As f_Main
End Module


2.In f_Main I've put this in method load:


Private Sub f_Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Mform = Me

3.In f_Key i added this:

Private Sub b_cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b_cancel.Click
Me.Close()
Mform.Close()
End Sub

Well, it closes both forms as i wish but displays this message box:

JIT Debugging

JIT Debugging failed with the following error: Access Denied

Please, i'll be very grateful if someone helps me.
 
Assuming that you want to close the application you suppose to join next code to the cancel button of f_Login form:

VB.NET:
Private Sub b_cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b_cancel.Click
Application.Exit()
End Sub

it will close the both including f_Main form

HTH
Regards ;)
 
Well, i've found a very old post which the same question here XDDDDD. Sorry XDDD.

The problem can be solved in a very very very easy way XDDDDDD. No extramodules, no extra-var...

Private Sub b_cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b_cancel.Click
Application.Exit()
End Sub

Cheers!
 
kulrom said:
Assuming that you want to close the application you suppose to join next code to the cancel button of f_Login form:

VB.NET:
Private Sub b_cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b_cancel.Click
Application.Exit()
End Sub
it will close the both including f_Main form

HTH
Regards ;)

XDDDDD, it seems i posted this at the same time XDDDD

Thanks Kulrom.
 
Back
Top