Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. button click

button click

Scheduled Pinned Locked Moved Visual Basic
question
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sonia Gupta
    wrote on last edited by
    #1

    hi, i have two buttons in my form - named button1 and button2.now in the following handler , can i add the two button click events? like private sub button_click(byval sender as system.objects , byval e as system.eventargs)handles button1.click , button2.click end sub

    _ C S 3 Replies Last reply
    0
    • S Sonia Gupta

      hi, i have two buttons in my form - named button1 and button2.now in the following handler , can i add the two button click events? like private sub button_click(byval sender as system.objects , byval e as system.eventargs)handles button1.click , button2.click end sub

      _ Offline
      _ Offline
      _Damian S_
      wrote on last edited by
      #2

      If clicking the two buttons causes the same code to execute, why do you need two buttons? ------------------------------------------- Damian - Man of changing signature.

      S 1 Reply Last reply
      0
      • _ _Damian S_

        If clicking the two buttons causes the same code to execute, why do you need two buttons? ------------------------------------------- Damian - Man of changing signature.

        S Offline
        S Offline
        Sonia Gupta
        wrote on last edited by
        #3

        No, further i want to do code to distinguish between two button , whether i have clicked button1 or button2 .Is it possible???????

        _ 1 Reply Last reply
        0
        • S Sonia Gupta

          No, further i want to do code to distinguish between two button , whether i have clicked button1 or button2 .Is it possible???????

          _ Offline
          _ Offline
          _Damian S_
          wrote on last edited by
          #4

          Yes, the sender parameter tells you which button was clicked. Check out the following link for details: http://www.samspublishing.com/articles/article.asp?p=102148&seqNum=3&rl=1[^]

          S 2 Replies Last reply
          0
          • _ _Damian S_

            Yes, the sender parameter tells you which button was clicked. Check out the following link for details: http://www.samspublishing.com/articles/article.asp?p=102148&seqNum=3&rl=1[^]

            S Offline
            S Offline
            Sonia Gupta
            wrote on last edited by
            #5

            I did not get the meaning of DirectCast(sender, Button) Private Sub LotsOfButtons( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles Button1.Click, Button2.Click, _ Button3.Click, Button4.Click, _ Button5.Click, Button6.Click, _ Button7.Click, Button8.Click, _ Button9.Click, Button10.Click Dim clickedBtn As Button If TypeOf sender Is Button Then clickedBtn = DirectCast(sender, Button) MsgBox(clickedBtn.Text) End If End Sub Should i imports any framework class to use this function?

            1 Reply Last reply
            0
            • _ _Damian S_

              Yes, the sender parameter tells you which button was clicked. Check out the following link for details: http://www.samspublishing.com/articles/article.asp?p=102148&seqNum=3&rl=1[^]

              S Offline
              S Offline
              Sonia Gupta
              wrote on last edited by
              #6

              is DirectCast(sender, Button) some sort of CTYpe(sender,button) ? If yes then DirectCast is any predefined function??????

              _ 1 Reply Last reply
              0
              • S Sonia Gupta

                is DirectCast(sender, Button) some sort of CTYpe(sender,button) ? If yes then DirectCast is any predefined function??????

                _ Offline
                _ Offline
                _Damian S_
                wrote on last edited by
                #7

                See this link: http://www.codeproject.com/useritems/DirectcastVsCtype.asp[^]

                1 Reply Last reply
                0
                • S Sonia Gupta

                  hi, i have two buttons in my form - named button1 and button2.now in the following handler , can i add the two button click events? like private sub button_click(byval sender as system.objects , byval e as system.eventargs)handles button1.click , button2.click end sub

                  C Offline
                  C Offline
                  Ch_Shahzad iqbal
                  wrote on last edited by
                  #8

                  Making the two function either it is user define e.g private sub button1_click(byval sender as system.objects , byval e as system.eventargs)handles button1.click and Change the Name Of Second Function and replace the Handeler name Button2 Please try it

                  1 Reply Last reply
                  0
                  • S Sonia Gupta

                    hi, i have two buttons in my form - named button1 and button2.now in the following handler , can i add the two button click events? like private sub button_click(byval sender as system.objects , byval e as system.eventargs)handles button1.click , button2.click end sub

                    S Offline
                    S Offline
                    shally_79
                    wrote on last edited by
                    #9

                    by using the following code you can distinguish between the two buttons Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click, Button5.Click Dim btn As Button = CType(sender, Button) If btn.Text = "ASDFS" Then Else End If End Sub

                    shally

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups