以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  窗口中如何引用一类控件  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=31698)

--  作者:kolen
--  发布时间:2013/4/19 9:59:00
--  窗口中如何引用一类控件
我的窗口中有控件lable 10个,textbox  10个,DropDownBox 20个。我想对20个控件 DropDownBox的 Enabled属性统一设置成FALSE,
请问,如何引用者20个控件?是否只有笨办法:
Dim FK As WinForm.DropDownBox = e.Form.Controls("付款方式DB")
FK.Enabled = false
....
这样引用20次,还是有代码一句可以解决到?


--  作者:Bin
--  发布时间:2013/4/19 10:07:00
--  

For Each c As Winform.Control In e.Form.Controls
    IF c.Gettype().ToString()="Foxtable.WinForm.DropDownBox" then

          c.Enabled =True

    end if
Next


--  作者:lsy
--  发布时间:2013/4/19 10:09:00
--  

For Each c As WinForm.DropDownBox In e.Form.Children
    c.Enabled = False
Next

 

For Each c As WinForm.Control In e.Form.Children

   If Typeof c Is WinForm.DropDownBox then

       c.Enabled = False

   End If
Next

 

 

 

如果用e.Form.Controls,碰到复合控件的时候,会把控件中的控件也遍历出来。

[此贴子已经被作者于2013-4-19 10:15:39编辑过]

--  作者:fox0001
--  发布时间:2013/4/19 10:15:00
--  
For Each c As WinForm.Control In e.Form.Controls
    If Typeof c Is WinForm.DropDownBox Then
        c.Enabled = False
    End If
Next

--  作者:Bin
--  发布时间:2013/4/19 10:16:00
--  
以下是引用lsy在2013-4-19 10:09:00的发言:

For Each c As WinForm.DropDownBox In e.Form.Children
    c.Enabled = False
Next

 

 

如果用e.Form.Controls,碰到复合控件的时候,会把控件中的控件也遍历出来。

如果不想把其他容器的控件也遍历出来.只需要遍历该容器的Childern即可 
For Each c As Winform.Control In e.Form.Controls("panel1").Children
    If c.Gettype().ToString()="Foxtable.WinForm.Button" Then
          c.Enabled =False
    End If
Next
[此贴子已经被作者于2013-4-19 10:16:44编辑过]

--  作者:lsy
--  发布时间:2013/4/19 10:19:00
--  
以下是引用Bin在2013-4-19 10:16:00的发言:

如果不想把其他容器的控件也遍历出来.只需要遍历该容器的Childern即可 
For Each c As Winform.Control In e.Form.Controls("panel1").Children
    If c.Gettype().ToString()="Foxtable.WinForm.Button" Then
          c.Enabled =False
    End If
Next
[此贴子已经被作者于2013-4-19 10:16:44编辑过]

不错。


--  作者:kolen
--  发布时间:2013/4/19 10:41:00
--  
谢谢!大家热情回复,学到很多!图片点击可在新窗口打开查看