我的程序有一個主窗體,其中保存了其他子窗體的值存儲庫。出於某種原因,子表單是給我的錯誤:如何將參數從1格式傳遞給另一格式?
an object reference is required for the non-static field
這是我的主要形式有:
public partial class frm_SystemLog : Form
{
public frm_SystemLog()
{
InitializeComponent();
}
public string TextBoxValue
{
// suppose to get value from other forms
get { return this.textBox1.Text; }
set { textBox1.Text = value; }
}
private void frm_SystemLog_Load(object sender, EventArgs e)
{
Log frm_LoginMenu = new Log();
frm_LoginMenu.ShowDialog();
}
}
這是我的子形式:
public partial class Log : Form
{
public Log()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
// this is where the error happens
frm_SystemLog.TextBoxValue = "SomeValue";
this.Close();
}
}
我必須創建一個觸發器變量,因爲當我回想起frm_SystemLog時,它會重新載入日誌表單...但代碼很有用。 –