c# pass value from current Form1 to Form2 shows error non static

183 views Asked by At
private void btn_justest_Click(object sender, EventArgs e)
{           
    using (var myForm = new FormShowResult())
    {
        myForm.Show();
        textBoxNameTest.Text = FormShowResult.TheValue;
    }
}

in Form 2:

public string TheValue
{
    get { return richtb_Show.Text; }
}

the problem is there is error "An object reference is required for the non-static field, method, or property" how to solve

My purpose to is call set an value to the parameter of Form2's Function, and load the function when start Form2.

2

There are 2 answers

0
Jason Watkins On

You need to use the myForm variable to access the instance, not the type name.

0
d.moncada On
  textBoxNameTest.Text = myForm.TheValue;