我想知道我应该如何编写我的 VB.net 应用程序以响应第三方应用程序中的表单加载事件(也是用 VB.net 编写的)
为了测试,我创建了两个基本程序,一个有两个表单(程序 A),一个(程序 B)尝试监听程序 A 的适当表单加载事件。我曾尝试使用 WithEvents,但在程序的第二个表单加载时它不会被触发。
这是程序 A 的代码:
Public Class StartPage
Public WithEvents loadtimer As New System.Windows.Forms.Timer
Private Sub StartPage_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
loadtimer.Interval = 1000
loadtimer.Enabled = True
loadtimer.Start()
End Sub
Private Sub loadtimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles loadtimer.Tick
loadtimer.Stop()
SystemStatus.Show()
End Sub
End Class
Public Class SystemStatus
Inherits StartPage
Private Sub StartPage_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Label1.Text = "This is the form that I want to listen for the load event"
Me.loadtimer.Enabled = False
End Sub
End Class
这是程序 B 的代码:
Imports Program_A
Public Class ListeningForm
Dim WithEvents testlisten As New Program_A.SystemStatus
Private Sub testlisten_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles testlisten.Load
Label1.Text = "SystemStatus form loaded"
End Sub
Private Sub ListeningForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = "Waiting for SystemStatus load event..."
End Sub
End Class
在编程方面我很新,所以也许这甚至是不可能的,或者我只是没有理解我一直在阅读的内容。无论如何,请告知我下一步应该采取的行动。
非常感谢提前,
theoleric