VB6执笔OCX在.NET WinForm的?OCX、WinForm、NET

2023-09-04 01:21:49 作者:把权天下

我继承VB6的项目,有一个表格用VB控件(标签等),Windows通用控件(树视图,ImageList中,等等),它看起来像一个用户控件的理想人选。

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.

我提到的一个同事编译它作为一个OCX ActiveX控件在.NET的WinForms项目中使用的可能性。他们稍微吓坏了,因为一个用VB OCX在C ++项目的previous经验:一切都在原型阶段的罚款,但有时间和用于对话框上实(很多控件时刷新的问题,对照组之间跳格,停用然后激活对话框,等等)。

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).

有没有人有使用撰写OCX一个.NET Windows窗体上的VB6的经验吗?我可以期待微妙的问题还是他们发挥好起来呢?

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?

推荐答案

我会很高兴地从.NET去href="http://www.$c$cproject.com/KB/vb-interop/VB6InteropToolkit2.aspx?fid=422404&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=26&select=2230658"相对=nofollow>互操作表单工具包2.0 从微软出于这样的目的。我已经做了很多次。走另一条路可能是痛苦的。

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.

想想看,你有一些.NET控件和VB 6主动X.此ActiveX也有它的控件NET的形式。现在,当你在你的.NET表单标签,当你到ActiveX你会那么的期望的标签来对所有的控件的在的该ActiveX,但你不知道!你会卡在整个ActiveX控件一次。这是一个问题。

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.

现在,如果你周围的其他方法去,.NET里面VB 6.0,你必须满足在code行为这一点。这 $ C $的CProject文章,具有优良的类称为ActiveXHelpers的做到了这一点。但基本上它归结为手工处理的关键pressed事件,检查标签或Shift + Tab,和手动聚焦下一个/ previous控制。

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.

现在你的情况,你会需要修改VB 6 code,以这样的表现。这将最有可能不太重写.NET中的控制作用。我从来没有经历过,令人耳目一新的问题,但就像我说我只走了.NET - > VB而不是相反。无论哪种方式,有可能会涉及到很多的痛苦,你将最有可能有其他的问题,比如下沉事件,告诉设计和运行时的VB之间的差异。

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.