开发者

VB.Net how to wait for a different form to close before continuing on

I have a little log in screen that pops up if a user selec开发者_运维知识库ts a certain item on my main form. How do I get my code to stop executing til my log in form closes?

This is what I am doing so far. Basically i want o execute the code after MyLogin closes.

    BMSSplash.MyLogin.Show()

    If isLoggedIn Then
        BMSSplash.MyBuddy.Show()
        Cursor.Current = Cursors.WaitCursor
    End If


One easy and reasonable option would be to show the form modally with ShowDialog instead of Show. This will block the rest of your application until the form is closed:

If BMSSplash.MyLogin.ShowDialog() = DialogResult.OK Then
    ' Form was closed via OK button or similar, continue normally... '
    BMSSplash.MyBuddy.Show()
Else
    ' Form was aborted via Cancel, Close, or some other way; do something '
    ' else like quitting the application... '
End If


Use BMSSplash.MyLogin.ShowDialog() instead to have the window shown as what is referred to as a modal dialog.


To stop other code from executing you need to show the other window as a modal dialog. This is typically done an WinForms type by calling the ShowDialog overload which accepts anIWin32Window` overload and passing the currently executing form. Typically Me.

BMSSplash.MyBuddy.ShowDialog(Me)

I don't have much experience with splash screen implementations though and it may have a slightly different API.


p.s. If you want to do .showDialog with a "splash" screen, you can add a timer on that form and have it me.dispose when the timer fires.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜