[英]How to pass a value from one Form to a private TextBox in another Form?
[英]How to pass data from one form to another form textbox in windows application?
我正在嘗試將變量從一種形式傳遞到另一種形式的文本框。 “變量”是基於用戶輸入的計算結果。
下面是父窗體(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;
}
}
下面是子窗體(Helpformula)的代碼,其中我將結果變量(formulainputs)傳遞給父窗體(RuleInsertForm)。
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中不會顯示。
到目前為止,我試圖將數據推回父表單,然后嘗試在失敗的文本框中顯示數據(我不知道哪里出了錯,建議我是否可以解決以下問題)
現在,我需要一種替代方法,例如:代替將數據推回父表單,我需要使變量可用於所有嘗試使用subform(formulainputs)的表單。
我該如何實現這個過程? 任何建議,不勝感激。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.