如何检查2文本框是否为空,如果是,则禁用按钮 [英] How to check if 2 textbox is empty and if they are, disable a button
本文介绍了如何检查2文本框是否为空,如果是,则禁用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我将下面的代码放在Private Sub Form_Load中,它不起作用但是如果我把代码放在ΟνομαTextBox中并且在ΚωδικοςTextBox中工作但是只有这个文本框我把代码放入。
我尝试了什么:
PrivateSubΟνομαTextBox_TextChanged(sender as Object,e作为EventArgs)处理ΟνομαTextBox.TextChanged
如果ΟνομαTextBox.Text=或ΚωδικοςTextBox.Text=那么
Button2.Enabled = False
否则
Button2.Enabled = True
结束如果
结束Sub
解决方案
您应该从两个文本框中处理TextChanged-Ebvent。
这可能是这样的:
私人 Sub TextBox_TextChanged(发件人作为 对象,e As EventArgs)句柄ΟνομαTextBox.TextChanged,ΚωδικοςTextBox.TextChanged
如果ΟνομαTextBox.Text= 或ΚωδικοςTextBox.Text= 然后
Button2.Enabled = False
其他
Button2.Enabled = True
结束 如果
结束 Sub
if I put the code below in Private Sub Form_Load, it doesnt work but if i put the code in ΟνομαTextBox works and in ΚωδικοςTextBox works but only for this textbox i put the code in.
What I have tried:
Private Sub ΟνομαTextBox_TextChanged(sender As Object, e As EventArgs) Handles ΟνομαTextBox.TextChanged If ΟνομαTextBox.Text = "" Or ΚωδικοςTextBox.Text = "" Then Button2.Enabled = False Else Button2.Enabled = True End If End Sub
解决方案
You should handle the TextChanged-Ebvent from both Textboxes.
That could be look like :
Private Sub TextBox_TextChanged(sender As Object, e As EventArgs) Handles ΟνομαTextBox.TextChanged , ΚωδικοςTextBox.TextChanged If ΟνομαTextBox.Text = "" Or ΚωδικοςTextBox.Text = "" Then Button2.Enabled = False Else Button2.Enabled = True End If End Sub
这篇关于如何检查2文本框是否为空,如果是,则禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文