如果VB中多个文本框中没有文本,如何禁用按钮? [英] How disable a button if there is no text in multiple textboxes in VB?

查看:60
本文介绍了如果VB中多个文本框中没有文本,如何禁用按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有9个一直称为 Textbox1 的文本框,一直到 Textbox9 .我还有一个名为 Letter 的按钮,该按钮从数组中选择一个随机字母.我还有一个名为开始的按钮.按下此按钮时,将显示一个计时器,从30秒开始一直递减为零.我希望只有在所有9个文本框中都包含文本的情况下才能使用此按钮.我尝试了以下操作,但似乎不起作用:

I have 9 TextBoxes called Textbox1 all the way to Textbox9. I also have a button called Letter which selects a random letter from an array. I have another button called Start. This button when pressed displays a timer counting down from 30 seconds all the to zero. I want this button to take place only if all the 9 textboxes have text in them. I tried the following but it did not seem to work:

推荐答案

将if语句中的所有"And"更改为"Or"

Change all of your "And" in your if statement to "Or"

Private Sub BtnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStart.Click
    If TxtBox1.Text = "" Or TxtBox2.Text = "" Or TxtBox3.Text = "" Or 
       TxtBox4.Text = "" Or TxtBox5.Text = "" Or TxtBox6.Text = "" Or
       TxtBox7.Text = "" Or TxtBox8.Text = "" Or TxtBox9.Text = "" Then
       TmrGame.Enabled = False
       MessageBox.Show("There Must Be A Total Of Nine Letters To Start The Game", "Not Enough Letters")
    Else
       TmrGame.Enabled = True
    End If
End Sub

通过使用And,您正在检查所有文本框必须为空,然后将timer.Enabled设置为false.使用或",您是说如果任何文本框为空,则将计时器设置为启用".

By using And, you're checking that all of the text boxes must be blank, then you'll set your timer.Enabled to false. With Or, you're saying if any of the text boxes are blank you'll set the timer.Enabled to false.

这篇关于如果VB中多个文本框中没有文本,如何禁用按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆