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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. RadioButton

RadioButton

Scheduled Pinned Locked Moved C#
tutorialquestion
13 Posts 4 Posters 1 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.
  • D DdoubleD

    Yes. What control do you want to change the text on when the RadioButton is selected?

    D Offline
    D Offline
    daffy_2003
    wrote on last edited by
    #4

    click, thanks for the reply.

    D 1 Reply Last reply
    0
    • B Blue_Boy

      On radioButton1_CheckedChanged event you can set text to label.


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

      D Offline
      D Offline
      daffy_2003
      wrote on last edited by
      #5

      change text to label ? thanks for the reply.

      1 Reply Last reply
      0
      • D daffy_2003

        click, thanks for the reply.

        D Offline
        D Offline
        DdoubleD
        wrote on last edited by
        #6

        "click" is an event. Do you want to change the text on the RadioButton, or a Label, or what? Anyway, just wire the event "click" event to the control, then inside it: radioButton1.Text = "my new text"; or labelText1.Text = "my new text"; etc.

        D 1 Reply Last reply
        0
        • D DdoubleD

          "click" is an event. Do you want to change the text on the RadioButton, or a Label, or what? Anyway, just wire the event "click" event to the control, then inside it: radioButton1.Text = "my new text"; or labelText1.Text = "my new text"; etc.

          D Offline
          D Offline
          DdoubleD
          wrote on last edited by
          #7

          For example: private void radioButton1_Click(object sender, EventArgs e) { radioButton1.Text = "my new text"; } but to wire the event: this.radioButton1.Click += new System.EventHandler(this.radioButton1_Click); which is done automatically by the designer, but if you don't have VS, just add the above to your form's constructor with a change to the radio button control's name of course that matches the method signature (e.g. "radioButton1_Click" in this case).

          D 1 Reply Last reply
          0
          • D DdoubleD

            For example: private void radioButton1_Click(object sender, EventArgs e) { radioButton1.Text = "my new text"; } but to wire the event: this.radioButton1.Click += new System.EventHandler(this.radioButton1_Click); which is done automatically by the designer, but if you don't have VS, just add the above to your form's constructor with a change to the radio button control's name of course that matches the method signature (e.g. "radioButton1_Click" in this case).

            D Offline
            D Offline
            daffy_2003
            wrote on last edited by
            #8

            hmmm, i did that, and when i go back to the previous form which has the radio button. The text of the radio button becomes the value that i type in the program. Exmaple, i click on Yes button, the value is Y but when i return back to the form, the text of the radio button becomes Y instead of Yes originally.

            D 2 Replies Last reply
            0
            • D daffy_2003

              hmmm, i did that, and when i go back to the previous form which has the radio button. The text of the radio button becomes the value that i type in the program. Exmaple, i click on Yes button, the value is Y but when i return back to the form, the text of the radio button becomes Y instead of Yes originally.

              D Offline
              D Offline
              DdoubleD
              wrote on last edited by
              #9

              Are you working with a Tabcontrol, or are you calling another form?

              1 Reply Last reply
              0
              • D daffy_2003

                hmmm, i did that, and when i go back to the previous form which has the radio button. The text of the radio button becomes the value that i type in the program. Exmaple, i click on Yes button, the value is Y but when i return back to the form, the text of the radio button becomes Y instead of Yes originally.

                D Offline
                D Offline
                DdoubleD
                wrote on last edited by
                #10

                Ooohh, I think you are calling a messagebox or another form. If so, you need to access the main form's (1st form, or parent form) control. Can you give me a code example?

                D 1 Reply Last reply
                0
                • D DdoubleD

                  Ooohh, I think you are calling a messagebox or another form. If so, you need to access the main form's (1st form, or parent form) control. Can you give me a code example?

                  D Offline
                  D Offline
                  DdoubleD
                  wrote on last edited by
                  #11

                  If that is the case (haven't seen your code yet), then here is an example of what you want I believe:

                          MyNewForm form2 = new MyNewForm();
                          DialogResult result = form2.ShowDialog();
                          if (result == DialogResult.Yes)
                              radioButton1.Text = "Yes";
                  

                  Note the "Text" being set after return from the previous form's "Yes" button, but you have to ensure the DialogResult being returned from form2 is DialogResult.Yes for this to work.

                  D 1 Reply Last reply
                  0
                  • D DdoubleD

                    If that is the case (haven't seen your code yet), then here is an example of what you want I believe:

                            MyNewForm form2 = new MyNewForm();
                            DialogResult result = form2.ShowDialog();
                            if (result == DialogResult.Yes)
                                radioButton1.Text = "Yes";
                    

                    Note the "Text" being set after return from the previous form's "Yes" button, but you have to ensure the DialogResult being returned from form2 is DialogResult.Yes for this to work.

                    D Offline
                    D Offline
                    daffy_2003
                    wrote on last edited by
                    #12

                    Hi. Thanks for helping me alot! =) but i figure it out already. Thanks. =D

                    1 Reply Last reply
                    0
                    • D daffy_2003

                      Hello, I wan to able to change the label when i select a radiobutton. For example when i select the Yes radiobutton, it will show the text as Y and not Yes. Is there a way to do that?

                      H Offline
                      H Offline
                      hosseinsinohe
                      wrote on last edited by
                      #13

                      use this code

                      if(radiobutton1.value==true){
                      {
                      radiobutton1.Text="Y";
                      }
                      else
                      {
                      rariobutton1.Text="Yes"
                      }

                      plz write this code in click event

                      Have a nice day

                      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