VB6 在 .NET WinForm 上编写了 ocx?

发布于 2024-08-09 17:36:21 字数 347 浏览 4 评论 0原文

我继承了一个 VB6 项目,该项目有一个带有 VB 控件(标签等)和 Windows 通用控件(Treeview、ImageList 等)的表单,它看起来像是用户控件的理想候选者。

我向一位同事提到将其编译为 ocx ActiveX 控件以便在 .NET WinForms 项目中使用的可能性。他们因为之前在 C++ 项目中使用 VB ocx 的经验而感到有点震惊:在原型设计阶段一切都很好,但在实际使用时存在计时和刷新问题(对话框上的许多控件、控件之间的 Tab 键切换、停用然后激活)对话框等)。

有人有在 .NET Windows 窗体上使用 VB6 编写的 ocx 的经验吗?我可以预料到一些微妙的问题吗?或者它们在一起能很好地发挥作用吗?

I've inherited a VB6 project that has a Form with VB controls (Label, etc) and Windows Common controls (Treeview, ImageList, etc), which looks like an ideal candidate for a usercontrol.

I mentioned to a colleague the possibility of compiling it as an ocx ActiveX control to be used in a .NET WinForms project. They were slightly horrified because of previous experience of using a VB ocx in a C++ project: everything was fine during the prototyping phase but there were timing and refresh problems when used for real (many controls on a dialog, tabbing between controls, deactivating then activating the dialog, etc).

Does anyone have any experience of using a VB6 authored ocx on a .NET Windows Form? Can I expect subtle problems or do they play nice together?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淑女气质 2024-08-16 17:36:21

我很乐意从 .NET 转向 -> VB 6.0 使用 Microsoft 的 Interop Forms Toolkit 2.0 正是出于此目的。我已经这样做过很多次了。走另一条路可能会很痛苦。

你的同事所担心的是非常真实的。出现的问题是哪个控制在哪个时间集中,以及如何在幕后处理某些想法。一个典型的例子是跨控件进行 Tab 键切换。

假设您有一个带有一些 .NET 控件的 .NET 表单和一个 VB 6 Active X。此 ActiveX 中也将包含控件。现在,当您在 .NET 表单上进行 Tab 切换时,当您访问 ActiveX 时,您可能会期望在 ActiveX 中的所有控件上进行 Tab 切换,但是您没有!您将立即通过选项卡浏览整个 ActiveX 控件。这是一个问题。

现在,如果您采用相反的方式,即 VB 6.0 中的 .NET,则必须在代码中满足此行为。这篇CodeProject 文章有一个名为 ActiveXHelpers 的优秀类,它可以做到这一点。但基本上它归结为手动处理 KeyPressed 事件,检查选项卡或 shift+tab,以及手动聚焦下一个/上一个控件。

现在,在您的情况下,您需要修改 VB 6 代码才能像这样运行。在 .NET 中重写控件很可能会更省力。我从未经历过令人耳目一新的问题,但就像我说的,我只使用过 .NET -> 。 VB 则不然。无论哪种方式,都可能会带来很多麻烦,并且您很可能会遇到其他问题,例如下沉事件以及区分 VB 中的设计和运行时之间的差异。

I would quite happily go from .NET -> VB 6.0 using the Interop Forms Toolkit 2.0 from Microsoft for exactly this purpose. I have done this many times. Going the other way could be painful.

What your colleague is concerned about is very real. The problem that comes in is which control is focused at which time and how certain thinks get handled under the hood. A prime example of this is tabbing across controls.

Consider that you have a .NET form with some .NET controls and a VB 6 Active X. This ActiveX would also have controls in it. Now as you tab across your .NET form, when you get to the ActiveX you would then expect to tab across all the controls in the ActiveX, but you don't! You will tab over the whole ActiveX control at once. This is a problem.

Now if you are going the other way around, .NET inside VB 6.0, you have to cater for behavior this in code. This CodeProject article, has an excellent class called ActiveXHelpers that does just that. But basically it comes down to manually handling the KeyPressed event, checking for a tab or shift+tab, and the focusing the next/previous control manually.

Now in your situation you'd need to modify the VB 6 code to behave like this. It'll most likely be less effort to rewrite the control in .NET. I've never experienced and refreshing problems, but like I said I've only gone .NET -> VB not the other way around. Either way there is likely to be lot of pain involved and you'll most likely have other issues, such as sinking events and telling the difference between design and runtime in VB.

彩虹直至黑白 2024-08-16 17:36:21

不幸的是我只有一半的答案。我们在 .NET 表单上使用单个 VB6 OCX 控件,它工作时没有任何问题。它不与该窗体上的任何其他 .NET 或 OCX 控件一起使用。它提供了数据库的专门视图。

Unfortunately I only have half an answer. We use a single VB6 OCX control on a .NET Form and it works without any issues. It is not used with any other .NET or OCX control on that form. It provides a specialized view into a database.

执妄 2024-08-16 17:36:21

在我们的软件套件中,我们混合了 VB6 和 .NET。我们在 VB.NET 和 C# 应用程序中使用许多 VB6 编写的 ActiveX 控件。在大多数情况下,它的效果出奇的好。

最让我们头疼的是,当VB6控件的版本发生变化时,我们必须在.NET项目中重新添加引用。 .NET 互操作库似乎与特定版本的控件相关联,如果不从项目中删除互操作并重新创建它们,它就无法为新版本重新生成互操作。有点痛苦,但我找到了方法,这样我就不必删除并重新创建控件的所有实例。

In our software suite we have quite the mix of VB6 and .NET. We use a number of VB6 authored ActiveX controls in both VB.NET and C# applications. For the most part, it works surprisingly well.

The biggest headache we have is that when the version of the VB6 controls change, we have to re-add the references in the .NET projects. It seems .NET interop libraries are tied to a specific version of the control and it can't regenerate the interop for a new version without removing the interops from the project and recreating them. A bit of a pain, but I've found ways of doing it so I don't have to remove and recreate all instances of the controls.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文