Send values from one form to another form

后端 未结 19 2795
眼角桃花
眼角桃花 2020-11-21 11:45

I want to pass values between two Forms (c#). How can I do it?

I have two forms: Form1 and Form2.

Form1 contains one button. When I click on that button, Fo

19条回答
  •  半阙折子戏
    2020-11-21 12:11

    Declare a public string in form1

    public string getdata;
    

    In button of form1

    form2 frm= new form2();
    this.hide();
    form2.show();
    

    To send data to form1 you can try any event and code following in that event

    form1 frm= new form1();
    form1.getdata="some string to be sent to form1";
    

    Now after closing of form2 and opening of form1, you can use returned data in getdata string.

提交回复
热议问题