2

in my application i have multiple forms form1 to form6 and i am switching between forms by hide and show method ,in form 3 i have multiple text box and check box and i need to get these text box data and check box status in form6 text box on button click event...

public partial class Form6 : Form
{

     Form3 _form3;
     Form4 _form4;
    public Form6()
    {
        InitializeComponent();
    }

    private void L_Click(object sender, EventArgs e)
    {

            _form3 = new Form3();

            string str1 = _form3.textBox1.Text;
            textBox21.Text = (str1 + Environment.NewLine).ToString();
            string str2 = _form3.textBox11.Text;
            textBox21.Text = (str2 + Environment.NewLine).ToString();

            int result1 = _form3.checkBox1.CheckState == CheckState.Checked ? 1 : 0;
            int result2 = _form3.checkBox11.CheckState == CheckState.Checked ? 1 : 0;
            int result3 = _form3.checkBox21.CheckState == CheckState.Checked ? 1 : 0;
            int result4 = _form3.checkBox31.CheckState == CheckState.Checked ? 1 : 0;
            int result5 = _form3.checkBox41.CheckState == CheckState.Checked ? 1 : 0;
            int result6 = _form3.checkBox51.CheckState == CheckState.Checked ? 1 : 0;
            int result7 = _form3.checkBox61.CheckState == CheckState.Checked ? 1 : 0;
            int result8 = _form3.checkBox71.CheckState == CheckState.Checked ? 1 : 0;
            int result9 = _form3.checkBox81.CheckState == CheckState.Checked ? 1 : 0;
            int result10 = _form3.checkBox91.CheckState == CheckState.Checked ? 1 : 0;

            textBox21.Text = (result1).ToString();
            textBox21.Text = (result2).ToString();
            textBox21.Text = (result3).ToString();
            textBox21.Text = (result4).ToString();
            textBox21.Text = (result5).ToString();
            textBox21.Text = (result6).ToString();
            textBox21.Text = (result7).ToString();
            textBox21.Text = (result8).ToString();
            textBox21.Text = (result9).ToString();
            textBox21.Text = (result10).ToString();
}
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user3413736
  • 163
  • 1
  • 4
  • 11

1 Answers1

0

Your problem is that you not reference the current instance of Form3 , rather than creating a new one, Try:

    Form3 form3;
    public Form6(Form3 form3)
    {
        InitializeComponent();
        this.form3=form3;
    }


 private void L_Click(object sender, EventArgs e)
    {
       int result1 = form3.checkBox1.CheckState == CheckState.Checked ? 1 : 0;
       int result2 = form3.checkBox11.CheckState == CheckState.Checked ? 1 : 0;
       //...
       //...   
    }
apomene
  • 14,282
  • 9
  • 46
  • 72