Calling a click event

In VB6 it was easy to call a controls click event ie (call textbox1_click). this however does not seem to work in Vb.Net 2005, any ideas

Cheers Kev




Answer this question

Calling a click event

  • etcheverrjc

    I found the best way was to put code in the gotfocus event of the combobox and call setfocus to initiate. After coding it was obvious that this is what I should have done in the first place, but trying to get my head around around OOP has made me loose sight of the easier stuff. 
    Cheers for all the replies guys.

    Kev


  • Aleksei

    You can also call the sub that handles the event.


    Public sub Main()
        Button1_Click(nothing, nothing)
    End sub

    Public sub Button1_Click(ByVal sender as Object, ByVal e as EventArgs) Handles Button1.Click

    End Sub

     



    Dustin


  • kristie

    Hi Guys,
    Would it not be more correct to refactor the code

    Example;




    Public sub Button1_Click(ByVal sender as Object, ByVal e as EventArgs) Handles Button1.Click

    Me.DoStuff()

    End Sub

    Public Sub DoStuff()
    'Do lots of stuff
    End Sub


     


    Then just call the DoStuff method rather than calling the button click event.

    Just a thought.

  • Mirek Sztajno

    Hi,

    you could use the PerformClick() method for a button to call the corresponding event:

    button1.PerformClick()

    Or you could directly call the function itself, just provide the parameters. Though, its not advisable...

     

    cheers,

    Paul June A. Domag



  • Krugger

    Hi,

    Yes, it would be more conveinient that way if your not using the parameters of the event (sender and e)...

     

    cheers,

    Paul June A. Domag



  • André Tadeu

    Cheers Justin thats got it


  • Calling a click event