¿Cómo disparo un evento en el código VB.NET?
Tengo un formulario que tiene un botón de inicio (para permitir que los usuarios ejecuten los procesos una y otra vez si lo desean), y deseo enviar unbtnStart.Click
Evento cuando se carga el formulario, para que los procesos se inicien automáticamente.
Tengo la siguiente función para elbtnStart.Click
evento, pero ¿cómo le digo a Visual Basic 'Pretender que alguien ha hecho clic en el botón y activar este evento'?
He intentado ir muy simple, lo que esencialmente funciona. Sin embargo, Visual Studio me da una advertencia.Variable 'sender' is used before it has been assigned a value
, así que supongo que esta no es realmente la manera de hacerlo:
Dim sender As Object
btnStart_Click(sender, New EventArgs())
También he intentado usarRaiseEvent btnStart.Click
, pero eso da el siguiente error:
'btnStart' no es un 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