3 回答
TA貢獻1862條經驗 獲得超6個贊
我認為這很簡單,我假設您有第一個名為 Form1 的表單和名為 Form2 的第二個表單。這個想法是使用這個函數來檢查并返回選中的值,并在重新打開 form2 時,將根據存儲的值選中或取消選中復選框:
在表格 2 中勾選 Modifiers = public
//Form 1
public bool status; // create global string to be accessed in form2
Form2 fm2 = new Form2(); // make an instance of form 2
fm2.stored_status = status; // assign the stored value to the getter and setter in form 2
fm2.ShowDialog(); // open form2 in dialog style
status = fm2.GetStatus(fm2.checkBox1); //call the function and store
// Form 2
public bool stored_status { get; set; } // define getter and setter
private void Form2_Load(object sender, EventArgs e)
{
if (stored_status) // check if stored value equal checked
checkBox1.Checked = true; // make the checkbox checked
else // if not
checkBox1.Checked = false; // keep it unchecked
}
public bool GetStatus(CheckBox check) // returns true of false and takes paramter of checkbox
{
if (check.Checked) // check if checkbox1 is checked
return true; // return true
else // if not
return false; // return false
}
- 3 回答
- 0 關注
- 472 瀏覽
添加回答
舉報
