How do I fire an event in VB.NET code?

前端 未结 4 1985
心在旅途
心在旅途 2020-12-31 02:57

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 btnStart.Click event when the form

相关标签:
4条回答
  • 2020-12-31 03:23

    You are trying to implement a bad idea. Actually, you have to make a subroutine to accomplish these kind of tasks.

    Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
    
          call SeparateSubroutine()
    
    End Sub
    
    private sub SeparateSubroutine()
    
       'Your code here.
    
    End Sub
    

    And then whereever you want to call the btnStart's click event, just call that SeparateSubroutine. This should be a correct way in your case.

    0 讨论(0)
  • 2020-12-31 03:30

    Steps in involved in raising an event is as follows,

    Public Event ForceManualStep As EventHandler
    RaiseEvent ForceManualStep(Me, EventArgs.Empty)
    AddHandler ForceManualStep, AddressOf ManualStepCompletion
    
    Private Sub ManualStepCompletion(sender As Object, e As EventArgs)        
    
    
    End Sub
    

    So in your case, it should be as below,

    btnStart_Click(btnStart, EventArgs.Empty)
    
    0 讨论(0)
  • 2020-12-31 03:31

    You should send a button as sender into the event handler:

    btnStart_Click(btnStart, New EventArgs())
    
    0 讨论(0)
  • 2020-12-31 03:31

    Just Call

    btnStart.PerformClick()
    
    0 讨论(0)
提交回复
热议问题