按钮启用和禁用文本更改事件

问题描述:

我想知道如何设置按钮以禁用文本框中是否没有文本,但是何时重新启用它呢?我可以将其放入文本更改事件中吗?

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?

类似的东西(WinForms):

Something like that (WinForms):

private void myTextBox_TextChanged(object sender, EventArgs e) {
  myButton.Enabled = !String.IsNullOrEmpty(myTextBox.Text);       
}

编辑:对于初始表单加载,您可以使用 Load 事件:

EDIT: For initial form load you can use Load event:

private void myForm_Load(object sender, EventArgs e) {
  myButton.Enabled = !String.IsNullOrEmpty(myTextBox.Text); 
}