Set value to another form

后端 未结 4 1694
清歌不尽
清歌不尽 2021-01-21 12:50

I have to form Form1 and Form2

Form1 source

namespace WindowsFormsApplication1
{
    public partial class Form1 :          


        
4条回答
  •  时光说笑
    2021-01-21 13:29

    public partial class Form1 : Form
    {
    public Form1() {
    InitializeComponent();
    }
    private void button1_Click(object sender, EventArgs e){
    Form2 frm = new Form2(this);
    frm.Show();
    }
    }
    public partial class Form2 : Form
    {
    Form _frm;
    public Form2(Form frm)
    {
    _frm = frm;
    InitializeComponent();
    }`enter code here`
    
    private void button1_Click(object sender, EventArgs e)
    {
    Form1 formVariable = (Form1)_frm;
    formVariable.textBox.Text = "Hello";
    }
    }
    

提交回复
热议问题