禁用窗体中的所有文本框 [英] Disable all TextBoxes in a Form
本文介绍了禁用窗体中的所有文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含4个文本框的表单.如何在编辑文本框后禁用所有其他文本框?
我无法预测要编辑哪个文本框.
I have a form with 4 textboxes.How can i disable all other textboxes after a textbox get edited?
i can''t predict which textbox get edited.
推荐答案
for each ctrl as control in me.controls
if typeof ctrl is textbox then
if not ctrl.name = sender.name then
ctrl.enable = false
end if
end if
next
您将需要在每个文本框textchanged或类似的事件中放入这样的内容
you will need to put something like this in each textboxes textchanged or similar event
这就是我的做法:
首先,我为所有文本框创建了一个通用的TextChanged事件.
This is how I did:
First I created a common TextChanged event for all the textboxes.
Private Sub TextChanged(sender As Object, e As EventArgs)
Dim txtEdit As TextBox = DirectCast(sender, TextBox)
For Each cntrl As Control In Me.Controls
If TypeOf cntrl Is TextBox AndAlso cntrl.Name <> txtEdit.Name Then
cntrl.Enabled = False
End If
Next
End Sub
}
然后注册:
And then register it :
Public Sub New()
InitializeComponent();
AddHandler(textBox1.TextChanged, AddressOf(TextChanged))
AddHandler(textBox2.TextChanged, AddressOf(TextChanged))
AddHandler(textBox3.TextChanged, AddressOf(TextChanged))
End Sub
希望对您有所帮助.
Hope it helped.
尝试一下:
try this:
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
TextBox1.Enabled = false;
TextBox2.Enabled = false;
TextBox3.Enabled = false;
TextBox4.Enabled = false;
}
这篇关于禁用窗体中的所有文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文