找到从C#msform所有控件 [英] Find all controls on msform from c#
本文介绍了找到从C#msform所有控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找到从C#使用VBA可扩展性互操作上msform所有控件
I'm trying to find all controls on msform from c# using VBA extensibility interop.
我可以找到使用各种形式的:</ p>
I can find all forms using :
using System;
using Microsoft.Office.Interop.Excel
using Microsoft.Vbe.Interop;
using Microsoft.Vbe.Interop.Forms;
.....
foreach (Microsoft.Vbe.Interop.VBComponent mycom in wb.VBProject.VBComponents)
{
if (mycom.Type == Editor.vbext_ComponentType.vbext_ct_MSForm)
.....
但我不能找到窗体上的控件。
but i can't find the controls on that form.
我想这应该是这个样子:
I think it should look something like :
....
foreach (Microsoft.Vbe.Interop.Forms.Control ctrl in Microsoft.Vbe.Interop.VBComponent.Designer.Controls)
....
但控件集合无法识别。
任何想法?
这线程提供的问题,我现在面临的更多信息:
This thread provides more information on problem I'm facing :
推荐答案
此代码应工作:
using System;
using Microsoft.Office.Interop.Excel
using VBA = Microsoft.Vbe.Interop;
...
VBA.Forms.UserForm form;
VBA.Forms.Control c;
foreach (VBA.VBComponent mod in wb.VBProject.VBComponents)
{
// Use only VBA Forms
if (!(mod.Designer is VBA.Forms.UserForm)) continue;
form = (VBA.Forms.UserForm) mod.Designer;
for (int i = 1; i < form.Controls.Count; i++)
{
c = (VBA.Forms.Control)form.Controls.Item(i);
...
}
}
这篇关于找到从C#msform所有控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文