![](/img/trans.png)
[英]How to change the Text of a Button in One form with a Button click of another Form?
[英]Click button for a text to appear in a another form textbox
我正在使用Visual Studio。 我有2種形式(formA和formB)。 在formA上有一個按鈕。 當我單擊它時,我希望一個單詞出現在formB上。 這就是formA.cs中的內容。 FormB是formB中的公共類名稱。
private void button1_Click(object sender, System.EventArgs e)
{
FormB search1 = new FormB();
search1.TextBox.Text = "test123";
}
但是,當我運行程序時,formB中沒有文本。 你能幫忙嗎?
使用參數在FormB上構造一個構造函數;
public FormB(string str)
{
InitializeComponent();
textBox1.Text = str;
}
然后從FormA初始化FormB並傳遞您的參數。
private void button1_Click(object sender, System.EventArgs e)
{
FormB search1 = new FormB("test123");
search1.Show();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.