我正在使用具有两种形式的 WinForm 应用程序。第一种形式是包含所有逻辑的主要形式。第二个表单包含一个浏览器控件,并根据从 Form1 传递的数据访问一个内部网页。然后可以与网页交互。当在 Form1 上弹出 MessageBox 时会出现问题,而在 Form2 上阻止了交互。
有没有办法在回答 MessageBox 之前启用 Form2 的交互?
OpenBrowser(docIDs, txtID.Text)
Me.Activate()
resultYESNO = MessageBox.Show(Me, questionText, "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If resultYESNO = DialogResult.Yes Then
columnValue = "Y"
ElseIf resultYESNO = DialogResult.No Then
columnValue = "N"
End If
OpenBrowser 子程序:
Private Sub OpenBrowser(ByVal docIDs As List(Of String), ByVal ID As String)
If Not Application.OpenForms().OfType(Of Browser).Any Then
Dim browser = New Browser()
End If
Dim encodeIDs As String
encodeIDs = String.Join(",", docIDs.ToArray())
Dim barray As Byte() = System.Text.Encoding.UTF8.GetBytes(encodeIDs)
Dim encodedIDs = System.Convert.ToBase64String(barray)
Dim url = ConfigurationManager.AppSettings("MyBrowserPath")
Browser.WebBrowser1.Url = New Uri(url & encodedIDs)
Dim area = Screen.PrimaryScreen.WorkingArea
Dim width = CInt(area.Width / 2)
Dim height = CInt(area.Height)
Browser.Width = width
Browser.Height = 800
Browser.SetDesktopLocation(width, 0)
Browser.Show()
Browser.BringToFront()
Browser.Activate()
End Sub
以下示例展示了如何创建不同的 UI 线程并在不同的线程上显示不同的表单。然后模态对话框表单在创建它们的线程中是模态的:
Imports System.Threading
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For i = 1 To 2
Dim index = i
Dim t = New Thread(
Sub()
Dim f = New Form With {.Text = $"Form {index}"}
Dim b = New Button With {.Text = "Click Me."}
AddHandler b.Click,
Sub()
Using d As New Form()
d.StartPosition = FormStartPosition.CenterParent
d.Size = New Drawing.Size(100, 100)
d.ShowDialog()
End Using
End Sub
f.Controls.Add(b)
Application.Run(f)
End Sub)
t.SetApartmentState(ApartmentState.STA)
t.IsBackground=True
t.Start()
Next
End Sub
End Class
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句