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. Windows Forms
  4. group of buttons

group of buttons

Scheduled Pinned Locked Moved Windows Forms
question
12 Posts 3 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.
  • P Polar_Sheep

    Hi, I have a project with 2 groups of buttons and I need assign to event on click to 1 group same piece of code and to 2 group another code. Solving it some component like GroupBox or someone?

    L Offline
    L Offline
    Luc Pattyn
    wrote on last edited by
    #2

    Hi, you can use the same Click handler for more than one Control. And if need be, cast sender to the right Control type to find out which Control fired the Click event. :)

    Luc Pattyn [Forum Guidelines] [My Articles]


    Voting for dummies? No thanks. X|


    P 1 Reply Last reply
    0
    • P Polar_Sheep

      Hi, I have a project with 2 groups of buttons and I need assign to event on click to 1 group same piece of code and to 2 group another code. Solving it some component like GroupBox or someone?

      T Offline
      T Offline
      Thomas Stockwell
      wrote on last edited by
      #3

      The other answer posted to this thread will work perfectly. Another option would be to create a new usercontrol for the groupbox control collection.

      Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios Discounted or Free Software for Students: DreamSpark - downloads.channel8.msdn.com MSDN Academic Alliance - www.msdnaa.com

      1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, you can use the same Click handler for more than one Control. And if need be, cast sender to the right Control type to find out which Control fired the Click event. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Voting for dummies? No thanks. X|


        P Offline
        P Offline
        Polar_Sheep
        wrote on last edited by
        #4

        Can you write that in code please? I need something like this to more powerful code: NOW: private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { } private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { } ... Future something like this: button 1-10_Click

        L 1 Reply Last reply
        0
        • P Polar_Sheep

          Can you write that in code please? I need something like this to more powerful code: NOW: private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { } private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { } ... Future something like this: button 1-10_Click

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #5

          replace button2_Click by button1_Click everywhere; replace button3_Click by button1_Click everywhere; replace button4_Click by button1_Click everywhere; replace button5_Click by button1_Click everywhere; replace button6_Click by button1_Click everywhere; replace button7_Click by button1_Click everywhere; replace button8_Click by button1_Click everywhere; replace button9_Click by button1_Click everywhere; replace button10_Click by button1_Click everywhere; everywhere also includes code autogenerated by Visual Studio. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          Voting for dummies? No thanks. X|


          P 1 Reply Last reply
          0
          • L Luc Pattyn

            replace button2_Click by button1_Click everywhere; replace button3_Click by button1_Click everywhere; replace button4_Click by button1_Click everywhere; replace button5_Click by button1_Click everywhere; replace button6_Click by button1_Click everywhere; replace button7_Click by button1_Click everywhere; replace button8_Click by button1_Click everywhere; replace button9_Click by button1_Click everywhere; replace button10_Click by button1_Click everywhere; everywhere also includes code autogenerated by Visual Studio. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            Voting for dummies? No thanks. X|


            P Offline
            P Offline
            Polar_Sheep
            wrote on last edited by
            #6

            Thank you, it works. But I have got still one little problem. I need take Button1->Text, ..., Button10->Text so I have something like that private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { textBox1->AppendText(buttonX ->Text); } How to change X?

            L 1 Reply Last reply
            0
            • P Polar_Sheep

              Thank you, it works. But I have got still one little problem. I need take Button1->Text, ..., Button10->Text so I have something like that private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { textBox1->AppendText(buttonX ->Text); } How to change X?

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #7

              Hi, as I told you before, you can cast sender to the right Control type to find out which Control fired the Click event. In your case, cast to Button, then use its Text property. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              Voting for dummies? No thanks. X|


              P 1 Reply Last reply
              0
              • L Luc Pattyn

                Hi, as I told you before, you can cast sender to the right Control type to find out which Control fired the Click event. In your case, cast to Button, then use its Text property. :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                Voting for dummies? No thanks. X|


                P Offline
                P Offline
                Polar_Sheep
                wrote on last edited by
                #8

                can you write it in code please?

                L 1 Reply Last reply
                0
                • P Polar_Sheep

                  can you write it in code please?

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #9

                  if you show your code, and specify its symptoms, CP members will help and pinpoint the problem(s). :)

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  Voting for dummies? No thanks. X|


                  P 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    if you show your code, and specify its symptoms, CP members will help and pinpoint the problem(s). :)

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    Voting for dummies? No thanks. X|


                    P Offline
                    P Offline
                    Polar_Sheep
                    wrote on last edited by
                    #10

                    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { textBox1->AppendText(System::Windows::Forms::ButtonBase::Text); } I do this code, but it still needs System::Windows::Forms::ButtonBase::Text as a static. I think I follow your definition - you can say that in values sender and e is everything what can we need.

                    L 1 Reply Last reply
                    0
                    • P Polar_Sheep

                      private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { textBox1->AppendText(System::Windows::Forms::ButtonBase::Text); } I do this code, but it still needs System::Windows::Forms::ButtonBase::Text as a static. I think I follow your definition - you can say that in values sender and e is everything what can we need.

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #11

                      you still need to take "sender", cast it to a Button and take its Text. :(

                      Luc Pattyn [Forum Guidelines] [My Articles]


                      Voting for dummies? No thanks. X|


                      P 1 Reply Last reply
                      0
                      • L Luc Pattyn

                        you still need to take "sender", cast it to a Button and take its Text. :(

                        Luc Pattyn [Forum Guidelines] [My Articles]


                        Voting for dummies? No thanks. X|


                        P Offline
                        P Offline
                        Polar_Sheep
                        wrote on last edited by
                        #12

                        textBox1->AppendText(this->ActiveControl->Text); Yipee! Fairness still exists :) Thank you so much

                        modified on Sunday, July 6, 2008 4:40 PM

                        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