提问人:ROY 提问时间:8/24/2023 最后编辑:ROY 更新时间:8/25/2023 访问量:38
[VB.NET][2008] 2 表格显示和关闭
[VB.NET][2008] 2 forms show and close
问:
我创建了 2 个表单并以不同的方法“显示”和“ShowDialog”显示它们。 我尝试关闭 Form2 Load 事件中的 Form1,Form2 的 DialogResult 更改为“Cancel”?这是一个错误吗?
F1 用于徽标显示,F2 用于登录窗口。 F1 显示并停留 3 秒。F2 显示并等待用户登录。
Private WithEvents f1 As Form
Private WithEvents f2 As Form
Private WithEvents bg As System.ComponentModel.BackgroundWorker
Public Sub Run()
Try
bg = New System.ComponentModel.BackgroundWorker
f1 = New Form
f1.Name = "Form1"
f1.Show()
Console.WriteLine("Show Form1 and stay 3 seconds")
bg.RunWorkerAsync()
f2 = New Form
f2.Name = "Form2"
Console.WriteLine("Show Form2 (ShowDialog)")
Dim rlt = f2.ShowDialog()
If rlt = DialogResult.Cancel Then
Console.ReadKey()
End If
Catch ex As Exception
End Try
End Sub
Private Sub bg_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bg.DoWork
Dim stw = Stopwatch.StartNew
Do
Application.DoEvents()
Loop Until stw.ElapsedMilliseconds > 3000
End Sub
Private Sub bg_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bg.RunWorkerCompleted
Console.WriteLine("Form2's DialogResult = {0}", f2.DialogResult)
f1.Close()
Console.WriteLine("After Form1 close, Form2's DialogResult changed to ({0}). WHY?", f2.DialogResult)
End Sub
#VB.NET
答: 暂无答案
评论
f1
f2