windows application c#

eagle_ea
eagle_ea used Ask the Experts™
on
Hello
i have 2 forms in windows application form.
1st form: has 3 radio button in a group box. and a button. once values is selected in the radio button and button is clicked, i want the text of the radio button selected to be passed from form 1 to form 2.
please help
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
what code do you have so far?

Author

Commented:
i only have the controls in place.

no code...Sorry :(
well ytou have a couple of options you can have a string property on form2 that you can set before you show form2 or you can pass it in a custom constructor on form2
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

Author

Commented:
i'm not familiar with either ways.
i found some examples on the web, which only passes value of one control.
can you please give me some examples.
thanks

Commented:
You should have make a RadioButton.CheckedEvent handler and have a public string value.

you string value:

string RadioButtonText = "";

in the event handlers for all Radiobuttons add this code:
{

 if (((RadioButton)sender).Checked)    
RadioButtonText = ((RadioButton)sender).Text;
}

The RadioButtonText variable contains the text of the Selected RadioButton

Author

Commented:
hmm...

but, this is just a couple of radio button's in a group box.

should i have this event for every single radio button?
both options in one example -- only choose one tho'

public partial class Form2 : Form
{
//the property way
public string SetText
{
     get
     {
           if(textBox!= null && !String.IsNullOrEmpty(textBox.Text))
                  return textBox.Text;
           else
                  return string.Empty;
       }
      set
      {
           if(textBox != null)
             textBox.Text = value;
      }

}

private string textToUse;
//the constructor way
public Form2(string text)
{
      InitializeComponents();
      textToUse = text;
}


//then in your formload event
{
     textBox.Text = text

}
}
oh -- for the property way

the instantiation would look like

Form2 form2 = new Form2();

form2.SetText = radiobuttontext;
form2.Show(this);
Commented:
You can add this code in your form.loaded event:

foreach(Control c in groupbox1.Controls)
{
   if(c is RadioButton)
    {
       c.CheckedEvent+= new EventHandler.....
    }

}

this would make a event handler for all radiobuttons in that Groupbox.

private void c.EventHandler(object sender, eventargs Args)
{

 You should post the code here for that i posted preivoously.
}

Author

Commented:
thank you both for your help. i took both your methods and got it done (i think)
below is the code.
form1:
 private void button1_Click(object sender, EventArgs e)
        {
            string radiotext = "";

            foreach (RadioButton list in groupBox1.Controls)
            {
                if (list.Checked == true) 
                {
                    radiotext = list.Text;
                }
            }

           
            Process pg = new Process();

            pg.SetText = radiotext ;
            pg.Show(this);
             
            
        }

form2:
public string SetText
        {
            get
            {
                if (groupBox1.Text != null && !String.IsNullOrEmpty(groupBox1.Text))
                    return groupBox1.Text;
                else
                    return string.Empty;
            }
            set
            {
                if (groupBox1.Text != null)
                    groupBox1.Text = value;
            }

        }

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial