vb.net Visual Basic 表单 .close() 方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15018421/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Basic form .close() method
提问by Dean
I have the below snippet of code:
我有以下代码片段:
'Handle level specific properties
Select Case ScoreCard.CurrentDifficulty
Case 1
intImageCount = 2 'This is the number of images to show at any given time on screen +1
'debug
ScoreCard.CurrentDifficulty = 6
Case 2
intImageCount = 3 'This is the number of images to show at any given time on screen +1
Case 3
intImageCount = 5 'This is the number of images to show at any given time on screen +1
Case 4
intImageCount = 2 'This is the number of images to show at any given time on screen +1
Case 5
intImageCount = 5 'This is the number of images to show at any given time on screen +1
Case 6
frmLevel3_HouseOfMirrors.Show()
Me.Close()
Return
End Select
When case 6is executed frm3_HouseOfMirrors.Show()executes and my new form opens. Me.closeexecutes as well but my problem is that the script then gets to the return line. Isn't me.Close()suppose to stop all execution of code on the current form and unload its self from memory?
当case 6执行frm3_HouseOfMirrors.Show()执行和我的新形式打开。Me.close也执行,但我的问题是脚本然后到达返回行。是不是me.Close()应该停止当前表单上的所有代码执行并从内存中卸载它自己?
回答by SysDragon
Just call frmLvl3_HouseOfMirrors.ShowDialog()instead of .Show(), this will stop the execution of code until the new form is closed.
只需调用frmLvl3_HouseOfMirrors.ShowDialog()而不是.Show(),这将停止代码的执行,直到新表单关闭。
Or if you want to cancel the execution of the rest of code try the Exitinstruction. You have to detect you want to finish and add it outside this Sub, because .Close()didnt stop the execution of code.
或者,如果您想取消其余代码的执行,请尝试Exit指令。您必须检测到您要完成并将其添加到 this 之外Sub,因为并.Close()没有停止代码的执行。
回答by Ben
No, the "close" method just closes the form, but the program execution will continue. If you want to stop code execution until a form is closed, you could make it modal.
不,“close”方法只是关闭表单,但程序会继续执行。如果您想在表单关闭之前停止代码执行,您可以将其设为模态。
In VBA it would look like this: frmLevel3_HouseOfMirrors.Show vbModal
在 VBA 中,它看起来像这样: frmLevel3_HouseOfMirrors.Show vbModal
回答by Konrad Rudolph
Isn't
me.Close()suppose to stop all execution of code on the current form and unload its self from memory?
是不是
me.Close()应该停止当前表单上的所有代码执行并从内存中卸载它自己?
No. Closedoes exactly what it says: it closes the visual, interactive representation of the form.1It doesn't affect code execution directly. It doesmake sure that Form_Closingand then Form_Closedare called, however. But the rest of the code execution is unaffected; in particular, the current method runs through normally. After that, other methods on the form may or may not be called as necessary (and, as mentioned, Closingand Closedwillbe called).
号Close不正是它说:它会关闭形式的视觉,交互表示。1它不直接影响代码执行。然而,它确实确保Form_Closing然后Form_Closed被调用。但其余的代码执行不受影响;尤其是当前方法运行正常。在此之后,在表单上的其它方法可以或可以不被称为必要(并且,如所提到的,Closing并且Closed将被称为)。
1And, yes, it releases the form's resources unless the form was shown via ShowDialograther than plain Show.
1而且,是的,它会释放表单的资源,除非表单是通过ShowDialog而不是普通显示的Show。

