大佬教程收集整理的这篇文章主要介绍了如何在VB.NET代码中触发事件?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有btnStart.Click事件的以下函数,但我如何实际告诉Visual Basic’假装有人点击了按钮并触发此事件’?
我试过非常简单,基本上可行.但是,Visual studio给我一个警告变量’sender’在被赋值之前被使用,所以我猜这不是真正的方法:
Dim sender As Object btnStart_Click(sender,New EventArgs())
我也尝试过使用RaiseEvent btnStart.Click,但是会出现以下错误:
码
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())
以上是大佬教程为你收集整理的如何在VB.NET代码中触发事件?全部内容,希望文章能够帮你解决如何在VB.NET代码中触发事件?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。