Problem calling form while closing the current one - vb.net

I am having problem closing current form when I call some other form from current one.
For example when I use code
me.dispose (I tried me.close too)
frmExam.ShowDialog()
It closes the current form but does not call frmExam.vb
How to fix it?
Thanks
Furqan

Show it and then close it!
frmExam.ShowDialog()
me.close()

Related

Unable to close VBA form

Real simple.
I have excel vba code which launches a form.
I have a close button on the form.
What would be the code to close the form?
Me.close doesn't work.
Indellisense doesn't seem to be giving me the right choice....
Unload Me is what I use. But you dont really need a close button. The user can just click the X in the top right corner.
if you wish to close the whole program then you should use
mainformname.close()
If you want to keep the main form open but hide the new form simply type
me.hide()

Program is running even after the close button pressed

I have a 2 form program,the first form's button click will open the second form when clicked. I tried using a .close() to hide the first form, but that ended the whole program. Then I tried using a .hide(). Now, when I click the X button in the top right of the second form, the program closes, but is still running in the background. How do I get around this?
By default, a VB.NET application will exit when you close the startup form. If you're hiding the startup form and closing the second form then the startup form is still open, so the app won't exit.
If you want to be able to close the first form without exiting the application then go into the project properties and set the shutdown mode to when all forms close instead of when the startup form closes. That way, you can show your second form and then close your first form. Closing the second form will then exit the app.
Simply close the main Form from inside the second form's FormClosed event.
Sub Form2_FormClosed(sender As Object, e As FormClosedEventArgs)
Form1.Close()
End Sub
You should use Me.Close() just before the ShowDialog() function for the second window.
if you want the 1st form to be visible again, add a form1.show() to the form_closing event of the 2nd form
if you want the program to end, add an Application.Exit to the form_closing event of the 2nd form

Difference form.Close() and form.hide()

What is the difference between form.Close() and form.Hide() in desktop application.
i know Form_Close event will not be fired in form.Hide() method what about other differences.
Is anyone faster?
form.Close() unloads the form from memory and makes it available to be garbage collected; you can no longer interact with the form in code.
form.Hide() just hides the form, but you can still interact with it in your code.
So it is not really a question of which one is faster, but rather "are you really done using this form or not"?
Hide makes the form invisible to the user. Close actually closes it and calls dispose on it.
From: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.close(v=vs.110).aspx
"When a form is closed, all resources created within the object are closed and the form is disposed. "
Hide only hides the form from the screen. Close is of course closes the form. If you want to get rid of the form that you don't want to use anymore then you should use Close. Hide and Close are different things.
Ditto the above... Typically the way you open the form determines which to use. If you use .Show() the calling code continues while the form is loaded and shown. If you use ShowDialog() then calling code stops while the form is loaded and shown. When you Hide the called form the calling code resumes to the next statement.
Here is a sample of the second case:
Dim frm As New frmSearch2
frm.inFormName = "frmFacility"
frm.ShowDialog(Me)
If frm.outPrimaryKey.Length > 0 Then
frmMain.Open_Form("frmFacility", frm.outPrimaryKey)
End If
frm.Close
frm = Nothing
outPrimaryKey is a form level Public variable. You can also address any of the controls on the form.

Keeping one form on top of the calling form

I'm using VB.NET (VS2008) and have a form (frmMain) that calls another form (frmCleanUp) but when frmCleanUp shows it can be hidden behind frmMain.
What I'd like to have is the new form be locked and have to close to get rid of it?
Thanks..
Show the Form with .ShowDialog() instead of .Show().
This way, the form is shown as modal dialog box and will stay on top until you close it.
when you show the form, do it with ShowDialog
in frmMain do:
frmCleanUp.ShowDialog

Problem with Me.Dispose and Me.Close

In certain forms I am having problems with my code. For example when I call frmTwo from frmOne, and want to close frmOne before frmTwo is shown, it does not work. I used code
(In frmOne I wrote)
Me.Dispose
frmTwo.Showdialoge()
frmOne closes but frmTwo does not appear.
If I do it otherwise,
frmTwo.Showdialoge()</pre>
Me.Dispose
In this case frmOne keeps running in the background, that I donot want.
Please advise how to manage it.
Thanks and best regards,
Furqan
It sounds like frmOne is marked as your main form. To accomplish what you wish to do you might try the following...
frmOne.Hide()
frmTwo.ShowDialog()
frmOne.Close()
That code will close the first form after the second form's dialog closes. If you are simply seeking to hide the first form, and then present it again after the second form has been closed, then you will want to use the following code instead...
frmOne.Hide()
frmTwo.ShowDialog()
frmOne.Show()
In addition to what recursion posted above, my understanding is tht the .close method of a form disposes of the form as well. Second, I don't think you can call Me.Dispose (can an object commit suicide?).
I can't check this out at the moment. However, beyond this minor elaboration, recusrion is on the money with his suggestions.