如何在 VB.NET 中查找 VB6 控件的类型
我正在编写一个 .NET DLL 来迭代通过引用传递的 VB6 表单中的所有控件。
到目前为止,它似乎可以工作 VB.NET 代码:
Public Sub AddFormRefLegacy(ByRef strAppName As String, ByRef objForm As Object)
'update the forms caption
objForm.Caption = FindValue(strAppName, objForm.Name, "", "0", objForm.Caption)
'iterate through all the controls on the form
For Each ctl As Object In objForm.Controls
if TypeOf ctl is Label then
'this doesn't pick up any labels
end if
Next
End Sub
从这个 VB6 代码调用:
Dim libDD As New Lib.clsDataDictionary
libDD.AddFormRefLegacy "nnne", Me
但 TypeOf 运算符不起作用。还有其他方法可以找到控件类型吗?
I am writing a .NET DLL to iterate through all controls in the a VB6 Form passed byref.
So far it seems to work VB.NET code:
Public Sub AddFormRefLegacy(ByRef strAppName As String, ByRef objForm As Object)
'update the forms caption
objForm.Caption = FindValue(strAppName, objForm.Name, "", "0", objForm.Caption)
'iterate through all the controls on the form
For Each ctl As Object In objForm.Controls
if TypeOf ctl is Label then
'this doesn't pick up any labels
end if
Next
End Sub
Called from this VB6 code:
Dim libDD As New Lib.clsDataDictionary
libDD.AddFormRefLegacy "nnne", Me
but the TypeOf operator does not work. Is there another way to find the type of control?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能正在比较两个不同的“标签”类型对象。
您尚未在 IF TYPEOF 行中限定 LABEL 类型,因此您可以将 VB6 标签与 .net 标签进行比较,但它们不会相同。
您可以使用 TYPENAME,但这可能并不完全是您所需要的。我会确保您确实在比较您认为正在比较的类型。
Could it be you're comparing two different "Label" type objects.
You haven't qualified the LABEL type in the IF TYPEOF line, so you could be comparing a VB6 label to a .net label, and they wouldn't be the same.
You could use TYPENAME, but that might not be exactly what you need iether. I'd make sure you're really comparing the types that you think you're comparing.
您是否尝试过使用 TypeName 函数?它是否返回任何对 TypeName(ctl) 有用的内容?
Have you tried using the TypeName function? Does it return anything useful for TypeName(ctl)?