Home > database >  button not clickable c# winforms
button not clickable c# winforms

Time:02-21

Is it possible to make a button not clickable and just make it clickable when a textbox was filled out, radio button was ticked, checkbox and combo box item was selected?(it needs to be all done before making the button clickable) I already made the button unclickable but I need to make it clickable after filling out informations. Please help, thank you

CodePudding user response:

One easy solution might be

  1. Disable your button on start up button1.Enabled=false

  2. Add events to your textbox etc. like TextChanged and with the following code.

         if (!textBox1.Text.Equals(string.Empty) && checkBox1.Checked && comboBox1.SelectedItem != null)
         {
             button1.Enabled = true;
         }
         else
         {
             button1.Enabled = true;
         }
    

That might work for your case here

CodePudding user response:

Since your question at this time does not contain code, I will refrain from adding code to the answer and offer you pseudocode to provide one of many possible solutions to this problem.

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
}

Now for each control you want to check add a listener for the appropriate Event to Ev_DoCheckEnableButton and voila.

CodePudding user response:

First put btnClickable to enable = false, then

basically you need to check if everything is as you need it to be, if it is as you wish, button is being enabled back.

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                if(cb1.Checked==true && tbText.Text!=null && rb1.Checked==true)
                {
                    btnClickable.Enabled = true; 
                }
            }

Note: This is an example where we use ComboBox - SelectionChanged method, because you wrote it last in the ln the question, so i assumed it goes last.

If, for example you want to put checkbox as the last item, just activate Click event on it, and change terms in if(). (ComboBox1.SelectedItem==null instead of cb1.Checked==true))

  • Related