加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何在VB.Net代码中触发事件?

发布时间:2020-12-17 00:12:22 所属栏目:大数据 来源:网络整理
导读:我有一个表单有一个启动按钮(允许用户一次又一次地运行这些进程),并且我想在表单加载时发送一个btnStart.Click事件,以便进程自动启动。 我对btnStart.Click事件有以下功能,但是如何实际告诉VB?假装有人点击了按钮并启动了这个事件? 我已经尝试过非常简
我有一个表单有一个启动按钮(允许用户一次又一次地运行这些进程),并且我想在表单加载时发送一个btnStart.Click事件,以便进程自动启动。

我对btnStart.Click事件有以下功能,但是如何实际告诉VB?假装有人点击了按钮并启动了这个事件?

我已经尝试过非常简单,这基本上是有用的。然而,Visual Studio给了我一个警告变量’发件人’被使用之前它已被分配一个值,所以我猜这不是真的做到这一点 –

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())

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读