title: How do I fire an event in VB.NET code?
body: <p>I have a form that has a start button (to allow users to run the processes over and over if they wish), and I want to send a <code>btnStart.Click</code> event when the form loads, so that the processes start automatically.</p>
  <p>I have the following function for the <code>btnStart.Click</code> event, but how do I actually tell Visual Basic 'Pretend someone has clicked the button and fire this event'?</p>
  <p>I've tried going very simple, which essentially works. However, Visual Studio gives me a warning <code>Variable 'sender' is used before it has been assigned a value</code>, so I'm guessing this is not really the way to do it:</p>
  <pre><code>Dim sender As Object
  btnStart_Click(sender, New EventArgs())
  </code></pre>
  <p>I have also tried using <code>RaiseEvent btnStart.Click</code>, but that gives the following error:</p>
  <blockquote>
  <p>'btnStart' is not an event of 'MyProject.MyFormClass</p>
  </blockquote>
  <h3>Code</h3>
  <pre><code>Imports 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 &gt;&gt;' 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
  </code></pre>