如何查明 VB6 控件是否在 .NET 中建立索引(控件数组)
我正在开发一个 VB.NET 项目,以使用 COM Interop 操作 VB6 表单。我的 VB6 表单上的某些控件已建立索引,有些则没有,因此对那些没有索引的控件调用 ctl.Index 会失败。有没有办法确定控件是否已索引?
I working on a VB.NET project to manipulate a VB6 form using COM Interop. Some of the controls on my VB6 form are indexed and some not, so calling ctl.Index fails on those that have no index. Is there a way to work out if a control is indexed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我已经设法用刀叉解决方案来使其发挥作用。但它的效率并不高,因为它每次都会遍历表单上的所有控件。我似乎记得在我的脑海里有一个VB6函数可以测试一个控件是否是一个数组,但我不记得了。对于任何感兴趣的人来说,我的功能如下,但如果可能的话,我仍然有兴趣找到一个更干净的解决方案?
如果有人感兴趣的话,下面是 VB6 的等效代码:
I have managed to knife and fork a solution to get this to work. But it isn't that efficient as it iterates through all controls on the form each time. I seem to remember at the back of my mind there is a VB6 function to test whether a control is an array but I can't recall it. My function for anyone who is interested is below but I would still be interested to find a cleaner solution to this if possible?
The Following is the VB6 Equivalent if anyone is interested:
我找到了一个类似于 @Matt Wilko 的解决方案,但它避免了循环遍历形式:
来源:http://www.vbforums.com/showthread.php?536960-RESOLVED-how-can-i-see-if-the-object-is-array-or-not
I found a solution similar to that of @Matt Wilko, but it avoids having to loop through all the controls on the form:
Source : http://www.vbforums.com/showthread.php?536960-RESOLVED-how-can-i-see-if-the-object-is-array-or-not
在 vb6 中,您可以使用 TypeName 函数 - 控件数组将返回类型“Object”,而不是实际的控件类型 - 如下所示:
In vb6 you can use the TypeName function - Control arrays will return type "Object", not the actual control type - like so:
如果控制数组只有一个成员,则上述解决方案不起作用。
测试控件是否作为控件数组成员的一个简单方法是测试控件的索引属性(控件数组)。这返回唯一标识控件数组中的控件的数字。仅当控件是控件数组的一部分时才可用。
The solutions proposed above do not work if there is only one member of the control array.
A simple way to test if a control as a member of a control array is to test for the control's Index Property (Control Array). This Returns the number that uniquely identifies a control in a control array. Available only if the control is part of a control array.