我有一个具有开始按钮的表单(允许用户根据需要反复运行进程),并且我想在表单加载时发送btnStart.Click事件,以便进程自动启动.
我有btnStart.Click事件的以下函数,但我如何实际告诉Visual Basic’假装有人点击了按钮并触发此事件’?
我试过非常简单,基本上可行.但是,Visual Studio给我一个警告变量’sender’在被赋值之前被使用,所以我猜这不是真正的方法:
Dim sender As Object btnStart_Click(sender,New EventArgs())
我也尝试过使用RaiseEvent btnStart.Click,但是会出现以下错误:
‘btnStart’ is not an event of ‘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
您应该将一个按钮作为发送者发送到事件处理程序中:
btnStart_Click(btnStart,New EventArgs())
原文地址:https://www.jb51.cc/vb/255956.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。