我想將一個變量從一個窗體傳遞給另一個窗體文本框。 「變量」是基於用戶輸入的計算結果。如何在Windows應用程序中將數據從一種窗體傳遞給另一種窗體文本框?
下面是父窗體(RuleInsertForm)的代碼,其中我調用子窗體(Helpformula)來獲取用戶輸入。
public partial class RuleInsertForm : Form
{
public string helpformulainputs;
}
private void RuleInsertForm_Load(object sender,EventArgs e)
{
if (helpformulainputs=="")
{
textBox_Inputs.Text = "";
}
else
{
textBox_Inputs.Text = helpformulainputs;
}
}
下面是其中i正經過結果變量(formulainputs),以母體形式(RuleInsertForm)窗體(Helpformula)的代碼。
public partial class HelpFormula : Form
{
public string formulainputs = string.Empty;
private void button_generateformula_Click(objectsender, EventArgs e)
{
using (RuleInsertForm insertform = new RuleInsertForm())
{
insertform.helpformulainputs = formulainputs;
this.Close();
insertform.Show();
}
}
}
問題: 的值獲得通過的文本框,但在UI其沒有得到dispalyed。
到目前爲止,我試圖把數據傳回父窗體,然後試着在我失敗的文本框顯示的數據。(我不知道哪裏出了問題建議我,如果我能解決下面的一個)
現在我需要一個替代方法,例如:而不是將數據推回父窗體我需要使變量可用於試圖使用子窗體的所有窗體(公式輸入)
如何實現此過程?任何建議都非常感謝。
真棒男人...非常感謝...它得到了工作..你節省了我的時間:)我將這標記爲答案:)_ –
只是一個qucik問題......這一個解決了我的問題..但現在即時通訊在UI顯示中有兩個insertform。我可以使用其他方法來處理這個問題,但是從您的結尾是否有任何建議? –
請參考我添加到我的答案中的鏈接或搜索詞。關於stackoverflow的線程已經有很多了。 –