2013-02-22 150 views
1

我的代碼下面的代碼片段:Visual Basic窗體.close()方法

'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 

case 6執行frm3_HouseOfMirrors.Show()執行和我的新形式打開。 Me.close也會執行,但我的問題是,腳本然後到達返回線。 me.Close()是不是假設要停止當前窗體上所有代碼的執行並從內存中卸載它自己?

回答

1

不,「關閉」方法只是關閉窗體,但程序執行將繼續。如果你想在表單關閉之前停止代碼執行,你可以使它成爲模態。

在VBA它應該是這樣的: frmLevel3_HouseOfMirrors.Show vbModal

+0

但是這是VB.NET所以你的代碼片段有點沒有意義 – 2013-10-18 13:35:24

2

只需撥打frmLvl3_HouseOfMirrors.ShowDialog()代替.Show(),直到新的形式被關閉,這將阻止代碼的執行。

或者如果要取消執行其餘代碼,請嘗試執行Exit指令。您必須檢測到您要完成並將其添加到Sub以外,因爲.Close()未停止執行代碼。

+0

@DeAn嗯?你刪除了正確的答案。沒有爲你工作?還需要什麼嗎? – SysDragon 2013-02-22 11:32:32

+0

嗨,現在就看這個。這部分工作。問題是,在執行打開的對話框窗口後,它返回到主窗口並繼續執行代碼,而不是完全關閉以前的窗體。它似乎只是暫停執行,這對我的情況並不理想。還有其他建議嗎? – 2013-02-26 10:21:11

+0

@DeAn你用'Exit'指令試過嗎?您可以退出該功能,循環或應用程序。把它放在'Me.Close'之後:例如'Exit Sub' – SysDragon 2013-02-26 10:30:52

0

是不是me.Close()假設停止當前窗體上的代碼的所有執行,並從內存中卸載自己?

No. Close確實如此:它關閉了窗體的視覺,交互式表示。 它不直接影響代碼執行。它確實確保Form_Closing然後Form_Closed被調用,但是。但其餘的代碼執行不受影響;特別是目前的方法正常運行。之後,表單上的其他方法可能會或可能不會被調用(如上所述,ClosingClosed將調用)。


而且,是的,它釋放形式的資源,除非形式通過ShowDialog,而不是普通的Show所示。

相關問題