Send values from one form to another form

后端 未结 19 2497
眼角桃花
眼角桃花 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:21

    if you change Modifiers Property of a control in a Form to Public, another Forms can access to that control. f.e. :

        Form2 frm;
        private void Form1_Load(object sender, EventArgs e)
        {
            frm = new Form2();
            frm.Show();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(frm.txtUserName.Text); 
            //txtUserName is a TextBox with Modifiers=Public        
        }
    

提交回复
热议问题