Jak odpalić zdarzenie w kodzie VB.NET?
Mam formularz, który ma przycisk startowy (aby umożliwić użytkownikom uruchamianie procesów w razie potrzeby), i chcę wysłaćbtnStart.Click
zdarzenie, gdy formularz ładuje się, aby procesy zaczęły się automatycznie.
Mam następującą funkcję dlabtnStart.Click
wydarzenie, ale jak właściwie powiedzieć Visual Basic'owi „Udawaj, że ktoś kliknął przycisk i wystrzelił to wydarzenie”?
Próbowałem iść bardzo prosto, co zasadniczo działa. Jednak Visual Studio daje mi ostrzeżenieVariable 'sender' is used before it has been assigned a value
, więc zgaduję, że tak naprawdę nie jest to możliwe:
Dim sender As Object
btnStart_Click(sender, New EventArgs())
Próbowałem również użyćRaiseEvent btnStart.Click
, ale daje to następujący błąd:
'btnStart' nie jest zdarzeniem 'MyProject.MyFormClass
KodImports System.ComponentModel
Partial Public Class frmProgress
Private bw As BackgroundWorker = New BackgroundWorker
Public Sub New()
InitializeComponent()
' Set up the BackgroundWorker
bw.WorkerReportsProgress = True
bw.WorkerSupportsCancellation = True
AddHandler bw.DoWork, AddressOf bw_DoWork
AddHandler bw.ProgressChanged, AddressOf bw_ProgressChanged
AddHandler bw.RunWorkerCompleted, AddressOf bw_RunWorkerCompleted
' Fire the 'btnStart.click' event when the form loads
Dim sender As Object
btnStart_Click(sender, New EventArgs())
End Sub
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
If Not bw.IsBusy = True Then
' Enable the 'More >>' button on the form, as there will now be details for users to view
Me.btnMore.Enabled = True
' Update the form control settings so that they correctly formatted when the processing starts
set_form_on_start()
bw.RunWorkerAsync()
End If
End Sub
' Other functions exist here
End Class