如何在不动态执行的情况下获取特定形式的控件名称 [英] How To get Controls names in specific form without dynamic execution
本文介绍了如何在不动态执行的情况下获取特定形式的控件名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚接触
并且可能是我的问题不对
当我想以特定形式获取所有控件名称时我使用以下
for me.controls中的每个ctrl
我将ctrl.name添加到表中以获取所有控件名称
但是如果有很多表单如200个表单我必须打开所有表单以获取当前项目中的所有控件名称
是否有任何包含控件名称的设计文件
i表示无需获取这些名称在运行时动态
解决方案
以下是:
公共 Sub ListFormControls()
Dim obj 作为 对象
Dim frm 作为表格
Dim ctl 作为控制
对于 每个 obj 在 Application.CurrentProject.AllForms
DoCmd.OpenForm obj.Name,acDesign ,,,, acHidden
设置 frm = Forms(obj.Name)
对于 每个 ctl 在 frm.Controls
Debug.Print frm.Name,ctl.Name
下一步
DoCmd.Close acForm,obj.Name,acSaveNo
下一页
设置 ctl = 没什么
设置 frm = 无
设置 obj = 没有
结束 Sub
在这里查看:枚举表单上的所有控件 [ ^ ]
试试C#代码:
var controlType = typeof (Control); // 或UserControl
var control = Assembly.GetExecutingAssembly()
.GetTypes()
.Where(t = > controlType.IsAssignableFrom (t)&&
t.Namespace == YourNameSpace)。ToList();
iam new to access
and may be my question is not right
when i want to get all controls names in specific form i am using the following
for each ctrl in me.controls
and i add ctrl.name to a table to get all controls names
but if have a lot of forms like 200 forms i have to open all the forms to get all controls names in the current project
is there any design file that contains controls names
i mean with out the need to get these names dynamically at run time
解决方案
Here is how:
Public Sub ListFormControls() Dim obj As Object Dim frm As Form Dim ctl As Control For Each obj In Application.CurrentProject.AllForms DoCmd.OpenForm obj.Name, acDesign, , , , acHidden Set frm = Forms(obj.Name) For Each ctl In frm.Controls Debug.Print frm.Name, ctl.Name Next DoCmd.Close acForm, obj.Name, acSaveNo Next Set ctl = Nothing Set frm = Nothing Set obj = Nothing End Sub
Have a look here: Enumerate all controls on a form[^]
Try C# code:
var controlType = typeof(Control);// or UserControl var control= Assembly.GetExecutingAssembly() .GetTypes() .Where(t => controlType.IsAssignableFrom(t) && t.Namespace == "YourNameSpace").ToList();
这篇关于如何在不动态执行的情况下获取特定形式的控件名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文