Como faço para disparar um evento no código VB.NET?
Eu tenho um formulário que tem um botão de início (para permitir que os usuários executem os processos várias vezes se quiserem), e eu quero enviar umbtnStart.Click
evento quando o formulário é carregado, para que os processos iniciem automaticamente.
Eu tenho a seguinte função para obtnStart.Click
evento, mas como eu realmente digo ao Visual Basic 'Finja que alguém clicou no botão e disparou este evento'?
Eu tentei ir muito simples, o que essencialmente funciona. No entanto, Visual Studio me dá um avisoVariable 'sender' is used before it has been assigned a value
, então eu estou supondo que esta não é realmente a maneira de fazer isso:
Dim sender As Object
btnStart_Click(sender, New EventArgs())
Eu também tentei usarRaiseEvent btnStart.Click
, mas isso dá o seguinte erro:
'btnStart' não é um evento de 'MyProject.MyFormClass
CódigoImports 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