Results 1 to 7 of 7

Thread: [RESOLVED]How to make a button click event happen from another sub?

  1. #1

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Resolved [RESOLVED]How to make a button click event happen from another sub?

    I have a sub procedure that I want to have act like it can click a button to make the button's procedures for the click event fire.
    Is there an easy way to do this or should I go about this differently?
    Thanks in advance.
    Last edited by gjon; Feb 17th, 2005 at 11:06 AM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to make a button click event happen from another sub?

    Post the code procedures. There are a few different ways. If its from another buttons click
    event you can just call the other command buttons event passing the sender and e arguments
    from the first buttons received arguments.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: How to make a button click event happen from another sub?

    VB Code:
    1. Private Sub btnTimeChnge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimeChnge.Click
    2.         timerVariable = tbxTimerLength.Text.ToString
    3.         tmrLoadPge.Interval = 60000 * timerVariable
    4.     End Sub

    Was thinking of having the timer call the button click.

    But then I realized I could use the timer to loop.

    VB Code:
    1. Private Sub tmrLoadPge_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrLoadPge.Tick
    2.         tmrLoadPge.Stop()
    3.         Process.Start(Me.lnkWebPages.Text)
    4.         tmrLoadPge.Start()
    5.     End Sub

    But I would still like to see it the way I originally asked about it.
    Thanks in advance.

  4. #4
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494

    Re: How to make a button click event happen from another sub?

    Something like this should do you:
    VB Code:
    1. Private Sub tmrLoadPge_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrLoadPge.Tick
    2.         tmrLoadPge.Stop()
    3.         Process.Start(Me.lnkWebPages.Text)
    4.         btnTimeChnge_Click(tmrLoadPge, e)
    5.         tmrLoadPge.Start()
    6.     End Sub

    It's just like calling any other method. You specify the name of the procedure and pass the required arguments. In this case, the object that is calling the event tmrLoadPge and then an event arguments class. The simplest way is to pass the event arguments of the timer event as per the example above.

    You could also use
    VB Code:
    1. btnTimeChnge_Click(tmrLoadPge, New EventArgs)

    This passes a new instance of the basic eventargs class.

    Some events have other types of eventargs classes associated with them so you may find things like calling a keypress event from code a little more complex, but here you're just fine with the default class.

    Hope this is what you're looking for.
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: How to make a button click event happen from another sub?

    Hi,

    Or

    Button1.PerformClick()
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  6. #6
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494

    Re: How to make a button click event happen from another sub?

    Oh yeah....forgot that simple one....

    Always looking for the complicated answer
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

  7. #7

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: How to make a button click event happen from another sub?

    LOL, awesome guys. Thanks. I will try to understand the passing of arguments by playing with your sample too.

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width