I am developing an application, in which there is a button in search box (like one in itunes).
I want to enable cancel button whenever there is text in text box and disable it when text box is empty.
I tried with text_changed event on textbox with the following code, but it jump over the if condition. Even sender sends me correct values but i am unable to put it into if else.
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(sender.ToString()))
{
btn_cancel.Visible = false;
}
else
{
btn_cancel.Visible = true;
}
}
Please help
Here is a simple solution.
Of course, you’ll have to set the button.Enabled = false when the form initially loads since the textbox event won’t fire on startup (true for all answers currently provided for your question).