Results 1 to 4 of 4

Thread: Using the same control code for two seperate controls

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2003
    Location
    Chicagoland
    Posts
    92

    Using the same control code for two seperate controls

    I hope that title is descriptive enough.

    I was showing one of my apps to my coworkers and they offered a little feedback. Basically the user fills out a form and hits the "submit" button. My boss suggested that there should be a submit button on the top as well as the bottom since the form is rather long and people that use lower resolutions might have to scroll down. Rather than argue with my boss, I'll do it.

    about 75% of my code is under the submit button control handler. I'd really rather not just cut and paste because that makes maintainabilty a pain. Is there a way to call the same code, without using a module, in a seperate control handler?

    I was just going to put in:
    Button7_Click()
    but they want two parameters to be passed with it. What should I pass? The full declaration is:
    Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

  2. #2
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    You can just add another Handles statement after your existing sub.

    VB Code:
    1. Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click, Button8.Click

    Now this sub will be executed both on button7 and button8 click.
    You can keep adding Handles statements for as many buttons as you need.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Or
    Call the eventhandler like this :

    VB Code:
    1. Button1_Click(Me, e)

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2003
    Location
    Chicagoland
    Posts
    92
    Thanks, both of you.

    I knew it would be something simple like that.

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