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.
Related
First of all I want to thank everyone who has helped me with answers here. You guys have been important in my development and for that you have my respect.
For the question: I want to create a form that displays the status for running multiple macros in sequence. For that i'm showing a form modelees so the macros continue running in the background.
The way I have it setup now, the form remains visible after macros are done.
Is there a way i can trigger the form to hide/unload when no macro is running?
Thanks,
Daniel
Just unload the form at the end of the last macro. I assume you have one calling sub which handles showing the form and calling the macros, so that is where I would also hide the progress form.
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.
I just want to connect two arbitrary controls, so that if one is clicked, the other should act as though it's clicked - is this even remotely possible? it seems like it SHOULD be so easy, but the internet seems dry, unless I just don't know how to ask the question properly... I see a way to "click" a button control, but what if the target is not a button? - I don't know the name of any function that might be triggered by this control's click event, so I can't call it directly. I would guess there is some way of using Windows APIs, but I can't find anything that's nice, simple VB
Example
I click a Label control on the form. I want to handle that click event, run one line of code, then simulate a click event on an associated RadioButton control
Is this possible? How?
If you must, call (System.Windows.Forms.Controls.)Control.InvokeOnClick
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invokeonclick%28v=vs.71%29.aspx
or even RadioButton.PerformClick
http://msdn.microsoft.com/en-us/library/system.windows.forms.radiobutton.performclick.aspx
A better way would be to create a common Subroutine that would be called on click of either controls. This way clicking on controls will execute their own code which can differ, and some common code as well.
This is how you accomplish executing the same code regardless of which control event was fired.
Private Sub ClickMe()
'code to execute
End Sub
Private Sub label1_Click(...) ...
ClickMe()
End Sub
Private Sub rb_checked(...) ...
ClickMe()
End Sub
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()
I'm developing a WinForms app in VB.NET, that handles sets of style data, and when the user clicks on another set's label, it prompts through a dialog "You are leaving this style preset to edit another one. keep changes on this one? [Yes] [No]"
But, I'm facing the problem that, when the user clicks either option, and the dialog closes, everything has to be refreshed, and loading the form again seems a good option.
I've tried putting a public sub on a module, that does this:
Public Sub CloseOpenStyleDlg()
KeepOrDiscardPrompt.Close()
StylesDlg.Close()
StylesDlg.ShowDialog()
End Sub
But as soon as that sub is called from the prompt, it crashes the application. (doesn't show an error in debug, simply crashes) How should I, from a given dialog, close the dialog, it's parent, and re-open it's parent? (which triggers all the Dialog_Load() code of the parent)
Thanks in advance! :)
You need to instantiate the dialog again. If I take your code for example:
Public Sub CloseOpenStyleDlg()
KeepOrDiscardPrompt.Close()
StylesDlg.Close()
StylesDlg = new StylesDlg()
StylesDlg.ShowDialog()
End Sub
When a form is closed, all resources created within the object are closed and the form is disposed.
If you want to reuse the Window instance use StylesDialog.Hide() function instead.