是否可以使按鈕不可點擊,而僅在填寫文本框、勾選單選按鈕、選中復選框和組合框專案時使其可點擊?(在使按鈕可點擊之前,這一切都需要完成)我已經做了該按鈕不可點擊,但我需要在填寫資訊后使其可點擊。請幫忙,謝謝
uj5u.com熱心網友回復:
一個簡單的解決方案可能是
在啟動時禁用您的按鈕
button1.Enabled=falseTextChanged使用以下代碼將事件添加到您的文本框等。if (!textBox1.Text.Equals(string.Empty) && checkBox1.Checked && comboBox1.SelectedItem != null) { button1.Enabled = true; } else { button1.Enabled = true; }
這可能適用于您的情況
uj5u.com熱心網友回復:
由于您此時的問題不包含代碼,因此我將避免在答案中添加代碼,并為您提供偽代碼以提供此問題的許多可能解決方案之一。
private void Ev_DoCheckEnableButton(object sender, EventArgs e)
{
//check here if textbox is filled, if radio button is ticked, if checkboed is checked and if combobox is selected
//if checks passed set the button to enabled
//if not passed then set it to disabled
}
現在,對于您要檢查的每個控制元件,將相應事件的偵聽器添加到 Ev_DoCheckEnableButton 并瞧。
uj5u.com熱心網友回復:
先把btnClickable設為enable = false,然后
基本上你需要檢查一切是否如你所愿,如果它如你所愿,按鈕正在被啟用。
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if(cb1.Checked==true && tbText.Text!=null && rb1.Checked==true)
{
btnClickable.Enabled = true;
}
}
注意:這是我們使用 ComboBox - SelectionChanged 方法的示例,因為您在 ln 問題中最后寫了它,所以我假設它最后出現。
例如,如果您想將復選框作為最后一項,只需在其上激活 Click 事件,然后更改 if() 中的術語。(ComboBox1.SelectedItem==null 而不是 cb1.Checked==true))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/429705.html
下一篇:C#不必要地添加00:00:00
