7,785
社区成员




Public Class Form1
Private stopped As Boolean
Private Sub oncancel(ByVal sender As System.Object, ByVal e As System.EventArgs)
stopped = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
stopped = False
Dim f As New Form2
f.canclose = False
f.Show(Me)
AddHandler f.Cancelled, AddressOf oncancel
Me.Enabled = False
For i As Integer = 0 To 100
If stopped Then Exit For
f.ProgressBar1.Value = i
Application.DoEvents()
Threading.Thread.Sleep(100)
Next
f.canclose = True
f.Close()
Me.Enabled = True
Me.Focus()
End Sub
End Class
Public Class Form2
Public Event Cancelled As EventHandler
Public canclose As Boolean = False
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RaiseEvent Cancelled(Me, Nothing)
canclose = True
Close()
End Sub
Private Sub Form2_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If Not canclose Then e.Cancel = True
End Sub
End Class