-3

Windows form application:

How can I get the value of textbox.text (Form1) in lbl.Text (Form2).

Gengaver
  • 5
  • 4

1 Answers1

0

Create a public value in Form 1, you will be able to get it's value on Form 2

//Form1.cs
public string val; 'create public value

Form1_Load()
{
    val = textbox.txt; 'load textbox value to val
}

//Form2.cs
Form2_Load()
{
    lbl.Text = Form1.val;
}
sora0419
  • 2,308
  • 9
  • 39
  • 58
  • I get the following error: – Gengaver Apr 08 '15 at 11:39
  • **An object reference is required for the non-static field, method, or property** – Gengaver Apr 08 '15 at 11:39
  • this is just some pseudo code to give you an idea, don't just copy and paste everything. There are different ways to do it, depends on if you are starting Form1 from Form2, or the other way around. Public value can allow you to pass value or reference a value from different form, though it might not be the best/most efficient way – sora0419 Apr 09 '15 at 01:54