Button enable and disable on text changed event

后端 未结 3 1310
囚心锁ツ
囚心锁ツ 2020-12-22 09:42

I am wondering how I can set a button to disable if there is no text inside a text box, but when there is re enable it? Would I put it into a text changed event?

3条回答
  •  轮回少年
    2020-12-22 10:11

    Did you mean something like this?

    if (!string.IsNullOrEmpty(textBox1.Text))
        button1.Enabled = true;
    else
        button1.Enabled = false;
    

    Don't forget that you can change the default property of that button.

提交回复
热议问题