pass a value from one form to another

后端 未结 7 1198
Happy的楠姐
Happy的楠姐 2020-11-27 21:10

I have two forms, and I need pass a value from form1.textbox1 to form2.variable

Form1:

string Ed = \"\", En = \"\"; 

public string En1
{
    get { r         


        
7条回答
  •  广开言路
    2020-11-27 22:00

    This can be achieved easily by creating an instance of Form 1 in Form 2. This is one of the approach.

    Follow the steps:

    In Form 1 : Make sure that your control is public.

        eg: txtForm1.Text = "Bangalore";  
    

    In Form 2 :

    Step 1: Create an instance of Form 1 globally. If the instance is created locally the value contained by the control cannot be accessed, only null value will be returned even the data has been populated to it.

    Step 2 : Retrieve the control's value by Form 1's instance.

     eg: Form1 frm1 = new Form1();
         string Form1Value = frm1.txtForm1.Text
    

提交回复
热议问题