How to pass string value from one form to another form's load event in C #

后端 未结 5 510
我寻月下人不归
我寻月下人不归 2020-12-03 15:12

I need to pass a string value from Form1:

public void button1_Click(object sender, EventArgs e)
{
    string DepartmentName = \"IT\";
    Form2          


        
5条回答
  •  难免孤独
    2020-12-03 15:48

    There is an easier way to pass the string from Form2 to Form1. Create a relationship between the forms and in Form2, create a variable of Form1, invoke the variable in Form1 and assign the value to it ....

    public partial class Form_2 : Form
        {
            public readonly Form1 _form1;
            public Form_2(Form1 form1)
            {
                _form1 = form1;
                InitializeComponent();
            }         
            private void Form2(object sender, EventArgs e)
            {     
                _form1.Remark = txtbx_remark.Text;                  
            }// Remark is a string in Form1 .... 
    

提交回复
热议问题