以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  如何根据窗口名称获取该窗体下所有按钮的名称?(已解决)  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=73946)

--  作者:jiterp
--  发布时间:2015/8/29 21:49:00
--  如何根据窗口名称获取该窗体下所有按钮的名称?(已解决)
如何写一行代码获取指定窗体名称下所有按钮的名称
[此贴子已经被作者于2015/9/6 16:45:40编辑过]

--  作者:有点蓝
--  发布时间:2015/8/29 21:52:00
--  
For Each c As WinForm.Control  In e.Form.Controls
  msgbox(c.Name)
Next

--  作者:jiterp
--  发布时间:2015/8/29 22:11:00
--  

If E.Form.Name = "窗口2" Then
Dim a As WinForm.CheckedComboBox = e.Form.Controls("CheckedComboBox1")
Dim s As String =""
For Each c As WinForm.Control In e.Form.Controls
s = s & "|" & c.name
Next
a.ComboList = s
End If

谢谢有点蓝,再问一下:我是按以上代码是取出了所有的控件的名称,可不可以只取出按钮的名称呀


--  作者:有点蓝
--  发布时间:2015/8/29 22:19:00
--  
http://www.foxtable.com/help/index.html?n=1849.htm
判断控件类型

--  作者:jiterp
--  发布时间:2015/8/29 22:46:00
--  

窗口3有三个按钮分别是Button1、Button2、Button3

在窗口2中设了两个控件:Button1和CheckedComboBox1,我希望在窗口2中执行Button1,CheckedComboBox1下拉框中的多选值分别是Button1、Button2、Button3。

 

我现在Button上写了以下代码,执行后,提示“未将对象引用设置到对象的实例。”错误,这是什么原因呀?

 

Dim sa As WinForm.Form = Forms("窗口3")

Dim a As WinForm.CheckedComboBox = e.Form.Controls("CheckedComboBox1")
Dim s As String
For Each c As WinForm.Control In sa.Controls
    If Typeof c Is WinForm.Button Then \'判断控件是否是按钮

        s = s & "|" & c.name
    End If
Next

a.ComboList = s


--  作者:有点蓝
--  发布时间:2015/8/29 22:57:00
--  
Dim sa As WinForm.Form = e.Form
--  作者:jiterp
--  发布时间:2015/8/29 23:20:00
--  
这个是获取当前窗口2的,我想获取窗口3的。
--  作者:jiterp
--  发布时间:2015/8/29 23:32:00
--  

自己捉摸出来了,在前面加上一个打开窗口动作,原来获取要打开窗口才可以的。

Forms("窗口3").Open

Dim sa As WinForm.Form = Forms("窗口3")

Dim a As WinForm.CheckedComboBox = e.Form.Controls("CheckedComboBox1")
Dim s As String
For Each c As WinForm.Control In sa.Controls
If Typeof c Is WinForm.Button Then \'判断控件是否是按钮

s = s & "|" & c.name
End If
Next

a.ComboList = s

Forms("窗口3").Close

[此贴子已经被作者于2015/8/29 23:31:54编辑过]