[VB.Net]一次清理所有文本框 [英] [VB.Net] To clear up all the textbox at one time

查看:84
本文介绍了[VB.Net]一次清理所有文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好:


我在一张表格上有20个,30个文本和组合框,我想一次清除

声明With .......... End With。


我在使用VB6时使用了这个,但我不知道我是否可以使用同样的方式

VB.Net。如果我不能在VB.Net中使用With语句,我该怎么办?


谢谢!!

解决方案

Dim ctrl As Control

Dim txt As TextBox


For each ctrl In Me.Controls

If( ctrl.GetType()是GetType(TextBox))然后

txt = CType(ctrl,TextBox)

txt.Text =""

结束如果

下一页

" KKuser" < A * @ c.d.com>。 ha scritto nel messaggio

新闻:O3 ************** @ TK2MSFTNGP09.phx.gbl ...

你好:

我在一个表单上有20个,30个文本和组合框,我想使用语句With ..........一次清除它们。结束于。

我在使用VB6时使用了这个,但我不知道我是否可以在VB.Net中使用相同的方式。如果我不能在VB.Net中使用With语句,我该怎么办?

谢谢!!



-----原始消息-----


您好

我使用以下程序清除文字。

他们使用System.Reflection


亲切的问候

Jorge


PS:用葡萄牙语...

Limpa = clean,meuform = myform,campos = field ...


Public Sub LimpaTextBoxes(ByVal f As Form)


Dim meuForm Type = f.GetType()

Dim campos As FieldInfo()= meuForm.GetFields

(BindingFlags.Instance或BindingFlags.NonPublic)

For Each campo As FieldInfo in campos

如果campo.FieldType.Name.ToLower =" textbox"

然后

Dim t As TextBox = DirectCast

(campo.GetValue(f),TextBox)

t .Text =""

结束如果

下一页

End Sub

Public Sub LimpaComboBoxes(ByVal f As Form)

Dim meuForm Type = f.GetType()

Dim campos As FieldInfo()= meuForm。 GetFields

(BindingFlags.Instance或BindingFlags.NonPublic)

For Each campo As FieldInfo in campos

如果campo.FieldType.Name.ToLower = combobox

然后

Dim c As ComboBox = DirectCast

(campo.GetValue(f),ComboBox)

c.Text =""

结束如果

下一页


End Sub


您好:

我在一个表单上有20个,30个文本和组合框,并且我想要使用
语句一次清除b $ b b 使用..........结束时。
我在使用VB6时使用了这个,但我不知道我是否可以在VBB中使用相同的方式
。如果我不能在VB.Net中使用With语句,我应该用
做什么?
谢谢!!



嗨KKuser,


看起来和其他人一样,但不是,它还会在

文本框时清除或者一个组合框放在另一个控件中,例如一个

组合框。


(我从别的东西改了它所以看错字)


我希望这有帮助吗?


Cor


Private Sub Form1_Load(ByVal sender As Object,_

ByVal e As System.EventArgs)Handles MyBase.Load

doclean(Me)

End Sub

Private Sub doSet( ByVal parentCtr As Control)

Dim ctr As Control

For each ctr in parentCtr.Controls

if typeof ctr is textbox then

ctr.txt =""

doSet(ctr)

elseif typeof ctr是combobox那么

ctr。 ''清理取决于这里,如果你使用itemarray或

数据源

下一页

结束子


Hello:

I have 20, 30 text and combo boxes on one form, and I would like to clear
them up at one time using the statement "With..........End With".

I used this when using VB6, but I don''t know if I can use the same way in
VB.Net. If I can''t use With statement in VB.Net, what should I do?

Thanks!!

解决方案

Dim ctrl As Control
Dim txt As TextBox

For Each ctrl In Me.Controls
If (ctrl.GetType() Is GetType(TextBox)) Then
txt = CType(ctrl, TextBox)
txt.Text = ""
End If
Next
"KKuser" <a.*@c.d.com> ha scritto nel messaggio
news:O3**************@TK2MSFTNGP09.phx.gbl...

Hello:

I have 20, 30 text and combo boxes on one form, and I would like to clear
them up at one time using the statement "With..........End With".

I used this when using VB6, but I don''t know if I can use the same way in
VB.Net. If I can''t use With statement in VB.Net, what should I do?

Thanks!!



-----Original Message-----
Hi
I use the following procedures to clear the text.
They use System.Reflection

Kind Regards
Jorge

PS: Its in Portuguese ...
Limpa=clean,meuform=myform,campos=field...


Public Sub LimpaTextBoxes(ByVal f As Form)

Dim meuForm As Type = f.GetType()
Dim campos As FieldInfo() = meuForm.GetFields
(BindingFlags.Instance Or BindingFlags.NonPublic)
For Each campo As FieldInfo In campos
If campo.FieldType.Name.ToLower = "textbox"
Then
Dim t As TextBox = DirectCast
(campo.GetValue(f), TextBox)
t.Text = ""
End If
Next
End Sub
Public Sub LimpaComboBoxes(ByVal f As Form)
Dim meuForm As Type = f.GetType()
Dim campos As FieldInfo() = meuForm.GetFields
(BindingFlags.Instance Or BindingFlags.NonPublic)
For Each campo As FieldInfo In campos
If campo.FieldType.Name.ToLower = "combobox"
Then
Dim c As ComboBox = DirectCast
(campo.GetValue(f), ComboBox)
c.Text = ""
End If
Next

End Sub

Hello:

I have 20, 30 text and combo boxes on one form, and I would like to clearthem up at one time using the statement "With..........End With".
I used this when using VB6, but I don''t know if I can use the same way inVB.Net. If I can''t use With statement in VB.Net, what should I do?
Thanks!!
.



Hi KKuser,

It looks the same as the others, however it is not, it cleans also when a
textbox or a combobox is places in another control as by instance a
groupbox.

(I changed it from something else so watch typos)

I hope this helps?

Cor

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doclean(Me)
End Sub
Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
if typeof ctr Is textbox then
ctr.txt = ""
doSet(ctr)
elseif typeof ctr Is combobox then
ctr. ''cleaning up depends here if you use the itemarray or the
datasource
Next
End Sub


这篇关于[VB.Net]一次清理所有文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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