其他文本框为空时禁用文本框

时间:2018-08-22 10:00:13

标签: vb.net

当“当前天”为空时,我试图禁用“基本费率”文本框 并在有一些数字时启用它。即时通讯有一个问题,当我把数字放在目前的日子,它将无法启用基本汇率的文本框。

Private Sub UserControlAdminPayroll_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    If txtPresentDays.Text = "" Then
        txtBasicRate.Enabled = False
    Else
        txtBasicRate.Enabled = True
    End If
End Sub

enter image description here

1 个答案:

答案 0 :(得分:2)

您需要每次检查txtPresentDays.Text的更改。试试这个:

Private Sub txtPresentDays_TextChanged(sender As Object, e As EventArgs) Handles txtPresentDays.TextChanged
    txtBasicRate.Enabled = Not String.IsNullOrEmpty(txtPresentDays.Text)
End Sub

别忘了在启动时将txtBasicRate.Enabled设置为适当的值。