在编辑另一个文本框后启用文本框 [英] Enable a textbox after another textbox edited

查看:100
本文介绍了在编辑另一个文本框后启用文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。



我尝试在Textbox1不再为空后启用文本框Textbox2。



我的代码是



如果TextBox1.Text =那么

TextBox2.Enabled = False

否则

TextBox2.Enabled = True

结束如果



但是当我键入Textbox1内部的东西Textbox2没有启用





事件是

 私有  Sub  Form1_Load(发件人作为 对象,e 作为 EventArgs)



内部一个TabPage

解决方案

你在哪个事件中这样做。你需要做这个按键事件。


因为你在Form_Load事件中有这个代码,所以你只设置 TextBox2



您还需要回复用户输入数据 TextBox1



可以把它放到 Private Sub TextBox1_KeyDown 事件中,但请注意每次按下用户时它都会运行一键。



我的偏好是只有当我们确定用户时才对 TextBox1 的内容采取行动已经完成了他们在该控件中所做的一切 - TextBox_Validated 事件很方便...

 < span class =code-keyword>私有  Sub  TextBox1_Validated( ByVal  sender 作为系统。对象 ByVal  e  As  System.EventArgs)句柄 TextBox1.Validated 
如果 .TextBox1.Text.Length> 0 然后
。 TextBox2.Enabled = True
否则
.TextBox2.Enabled = 错误
结束 如果
结束 Sub


Hi there.

I try to enable a textbox "Textbox2" after the "Textbox1" is no more empty.

My code is that

If TextBox1.Text = "" Then
TextBox2.Enabled = False
Else
TextBox2.Enabled = True
End If

But when i type something inside the Textbox1 the Textbox2 does not enable

[EDIT - OP comment moved from solution]
Event is

Private Sub Form1_Load(sender As Object, e As EventArgs)


Inside a TabPage

解决方案

In which event are you doing this. you need do this key down event.


Because you have this code in the Form_Load event you are only setting the initial state of the TextBox2

You also need to respond to the user entering data into TextBox1

You could put this into the Private Sub TextBox1_KeyDown event, but note that it would run each time the user pressed a key.

My preference is to act on the contents of TextBox1 only when we are sure that the User has finished whatever they are doing in that control - The TextBox_Validated event is handy for that...

Private Sub TextBox1_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Validated
    If Me.TextBox1.Text.Length > 0 Then
        Me.TextBox2.Enabled = True
    Else
        Me.TextBox2.Enabled = False
    End If
End Sub


这篇关于在编辑另一个文本框后启用文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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