0

i have passes some values though a constructor from one from to another. the values are successfully transferred in another form through constructor but when i display them in a textbox the values become null and the textbox remains empty. i am showing the code of the constructor for both forms.

starting form which opens another form

 private void lbl_imgpass_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
        string img = img_name.Text;
        Setimgpass st = new Setimgpass(img);
        st.Show();
    }

form1(from where the values are transferred to another form)

  else
        {
             first = textBox2.Text;
             second = textBox3.Text;
             third = textBox4.Text;
             Adduser add = new Adduser(x1low, x1up, x2low, x2up, x3low, x3up, y1low, y1up, y2low, y2up, y3low, y3up, first, second, third);
          this.Hide();

        }

second form(where the values are received)

     public Adduser(string x1low, string x1up, string x2low, string x2up, string x3low, string x3up, string y1low, string y1up, string y2low, string y2up, string y3low, string y3up,string first, string second, string third)

        {
          InitializeComponent();
          frst = first;
          secnd = second;
          thrd = third;
          lowx1 = x1low;
          upx1 = x1up;
          lowx2 = x2low;
          upx2 = x2up;
          lowx3 = x3low;
          upx3 = x3up;
          lowy1 = y1low;
          upy1 = y1up;
          lowy2 = y2low;
          upy2 = y2up;
          lowy3 = y3low;
          upy3 = y3up;
          txt_imgpass.Text = frst + " " + secnd + " " + thrd;

      }

txt_imgpass is the textbox in which i want values.

1 Answers1

0

In the first form the values are passed to the object "add" that you created .

You can simply use static variables to pass data from one form to another .

EDIT

You might as well want to try something like this instead of static variables

Form 1 : assuming this is the button you click on to show the second form

private void button1_Click(object sender, EventArgs e)
    {
        Form2 form = new Form2(textBox1.Text);
        form.Show();
    }

in Form 2 you can do something like this

public Form2(string text)
    {
        InitializeComponent();

        label1.Text = text;
    }
M. Baza
  • 44
  • 6
  • thanks but i am bit confused about these static variables so please can you help in declaring them how can i make them static variables and access them in another form. – Utkrisht Srivastav Mar 26 '16 at 23:34
  • can you please explain further more how your first form look like and the second form two – M. Baza Mar 26 '16 at 23:59
  • i have edited my code now have a look at it actually one form is opening on the click of a label without hiding the previous form then in that values are entered and when clicking on save button the values are passed through a constructor and second form is hidden and the previous form is seen which was not hidden – Utkrisht Srivastav Mar 27 '16 at 00:04
  • everything looks fine to me , just as Steve said all you need is to show the form , add.Show(); – M. Baza Mar 27 '16 at 00:11
  • let me show you the control flow its user register -> form2 -> user register so according to you when i use add.show() the values which were already present on user register previously are gone and only the current value in the textbox remains i hope now you have understood what i wanted to say? – Utkrisht Srivastav Mar 27 '16 at 00:25
  • by static variable: In Form1: 'static string str;' and initialize 'str'. In Form2: 'new Form1 f1 = New Form1();' and 'label1.Text = f1.str' – PLOW Mar 27 '16 at 01:56