亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C# 復選框選中/取消選中關閉窗口

C# 復選框選中/取消選中關閉窗口

Go
揚帆大魚 2021-06-27 07:45:20
我希望我能解釋一下,對不起,文字會用不同的語言。我想要做的是我有兩個窗口,一個是主窗口,另一個是用于保存 csv 文件。在我當前的程序中,當我選中復選框并單擊“確定”按鈕時,它會起作用,但關閉后復選框將被取消選中,但我需要在打開后保持選中復選框,以便我可以輕松找出上次選中的內容。我的窗戶是這樣的:
查看完整描述

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

}


查看完整回答
反對 回復 2021-07-03
  • 3 回答
  • 0 關注
  • 472 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號