開始ボタンのあるフォームがあり (ユーザーが必要に応じてプロセスを何度も実行できるようにするため)、btnStart.Click
プロセスが自動的に開始されるように、フォームが読み込まれたときにイベントを送信したいと考えています。
イベントに対して次の関数がありますが、btnStart.Click
実際に Visual Basic に「誰かがボタンをクリックしたふりをしてこのイベントを発生させる」ことを伝えるにはどうすればよいですか?
私は非常にシンプルにしようとしましたが、これは本質的に機能します。ただし、Visual Studio は警告Variable 'sender' is used before it has been assigned a value
を表示するので、これは実際にはそれを行う方法ではないと推測しています。
Dim sender As Object
btnStart_Click(sender, New EventArgs())
も使用してみRaiseEvent btnStart.Click
ましたが、次のエラーが発生します。
「btnStart」は「MyProject.MyFormClass」のイベントではありません
コード
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 >>' 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