How to change text in a textbox on another form in

2019-01-12 07:31发布

In Visual C# when I click a button, I want to load another form. But before that form loads, I want to fill the textboxes with some text. I tried to put some commands to do this before showing the form, but I get an error saying the textbox is inaccessible due to its protection level.

How can I set the textbox in a form before I show it?

 private void button2_Click(object sender, EventArgs e)
    {

        fixgame changeCards = new fixgame();
        changeCards.p1c1val.text = "3";
        changeCards.Show();


    }

7条回答
叛逆
2楼-- · 2019-01-12 08:21
private void button1_Click(object sender, EventArgs e)
{    
    Form2 frm = new Form2();
    TextBox txt = (TextBox)frm.Controls.Find("p1c1val", true)[0];
    txt.Text = "foo";
}
查看更多
登录 后发表回答