CAN /你怎么主机在C#WPF应用程序的完整VB6的形式? [英] Can/how do you host a full VB6 Form in a C# WPF app?

查看:229
本文介绍了CAN /你怎么主机在C#WPF应用程序的完整VB6的形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在探索移植一些旧VB6应用程序与WPF C#的选项。该计划在第一阶段,是港口的几个关键形式,而不是所有的应用程序。理论目标是通过一个ActiveX DLL某种内WPF的容器,打开VB6的形式。

I am currently exploring the option of porting some older VB6 application to WPF with C#. The plan, in phase one, is to port several key forms and not all the application. The theoretical goal is to open the VB6 form in a container of some sort within WPF via an ActiveX dll.

这甚至可能吗?
我试图寻找在互操作和似乎无法找到它如何获得与任何工作的坚实的例子,但Win32的控制,而不是一个完整的形式。我有充分的机会旧VB6代码,可以在总需要修改

Is this even possible? I've tried looking at the Interop and can't seem to find a solid example of how get it to work with anything but Win32 controls, not a full form. I have full access to the old VB6 code and can modify it in anyway needed.

主要WPF应用程序下面的截图将作为包装/容器:

The following screenshot of the main WPF app would serve as the wrapper/container:

http://www.evocommand.com/ junk_delete_me / main_menu_mockup.png

这将白色空间一节中装载的上一画面右侧当前VB6维护屏幕。

The current VB6 maintenance screen that would be loaded in the "white space" section on the right side of the previous screen.

推荐答案

我可以通过以下步骤来完成任务:

I was able to accomplish the task with the following steps:


  1. 创建一个新的VB6的Active X控件项目。复制和粘贴VB6的表单控件和代码的全部内容后面到新的控制。有迹象表明,在切换到控制处理几个要素:

  1. Created a new VB6 Active X Control Project. Copied and pasted the entire contents of the VB6 form controls and code behind into the new control. There are several elements that have to be handled in switching to a control:


  1. 在输给显示
    的能力在
    以往的方式形式的标题。您可以解决
    它与备用控制
    (标签/ borderlesstextbox等)是
    完成同样的功能,如果
    需要。这不是一个优先事项,因为
    每个屏幕是在一个
    浏览器,如标签系统主持在我们新的
    .NET项目。

  1. you lose the ability to display the caption of the form in the previous manner. You can work around it with alternate controls (label/borderlesstextbox, etc) that accomplish the same functionality if needed. This wasn’t a priority since each screen was being hosted in a browser like tab system in our new .Net project.

所有的MousePointer引用都为
从Me.Mousepointer改为
Screen.mousepointer

All mousepointer references have to be changed from Me.Mousepointer to Screen.mousepointer

您不能使用我.Hide并有
备用事件隐藏的.Net
容器中。

You cannot use Me.Hide and have to alternate events to hide the .Net container.

任何和b $ b我到$所有引用[什么]已被删除或
与用户控件取代。[什么]
如果他们是适用的。

Any and all references to Me.[anything] have to be removed or replaced with UserControl.[anything] if they are applicable.

如果您使用即
参考任何功能的
[yourcontrol] .Contianer.Property一个
组成,他们将需要通过UserControl.Controls
集合进行修改,以
环,而不是和集装箱是VB6 ActiveX控件
无效

If you use any functions that reference a [yourcontrol].Contianer.Property on a form they will need to be altered to loop through the UserControl.Controls collection instead and "Container" is invalid for vb6 ActiveX controls

所有非模态窗体/对话框
必须从项目中删除为
现在也没有HWND在WPF来处理。
你得到的错误'非模态窗体
不能显示在从一个ActiveX DLL,
ActiveX控件或属性页该主机
应用。
在这里,我们有一个简单的飞溅
画面时,一定
长流程/报告中显示为
让用户知道发生了什么运行,将显示。

All non-modal forms/dialog boxes must be removed from the project as there is now no Hwnd to handle in WPF. You get an error of 'Non-modal forms cannot be displayed in this host application from an ActiveX DLL, ActiveX Control, or Property page'. In our case we had a simple splash screen that would display when certain long processes/reports displayed to let the user know what was running.

我无法直接通过互操作加上VB6控制到WPF项目。作为这种新的.NETWindows窗体控件库项目被创建。对VB6 OCX的引用添加到项目中。然后,VB6 CONTROL S被右键点击添加到.NET工具箱 - >添加项目,并指着一个COM参考VB6控制OCX。然后,将.NET控件用于承载/服务VB6控制。

  • I was unable to directly add the VB6 control via the interop to a WPF project . As such a new .Net "Windows Form Control Library" project was created. A reference to the VB6 OCX was added to the project. The VB6 Control s were then added to the .Net toolbox by "right click" –> "Add Item" and pointing a com reference to the VB6 control ocx. The .Net control was then used to host/serve the VB6 Control.

    要显示主机在VB6形式,并得到它火必要的初始化功能,所以他们的VB6 OCX控件被拖欠的Visible.False方式最初加入到净OCX为不可见的控制。当需要时VB6的控制设置为可见= true时,这触发UserControl_Show()事件。在所有的Form_Load原代码()被转移到这个事件。展会活动是根据需要访问的Form_Load的最简单的方法。 MSDN:控制不接收显示事件如果窗体被隐藏,然后再次显示,或者如果窗体最小化,然后还原。该控件的窗口时这些运算保留在表上,它的Visible属性不会改变。

    To display host a form in the VB6 and get it to fire the necessary initialization functionality the VB6 OCX controls were defaulted in a Visible.False manner so they were initially added to the .Net OCX as invisible controls. When needed the VB6 control is set to visible = True which fires the UserControl_Show() event. All code formerly in Form_Load() was moved to this event. The show event was the easiest method of accessing the Form_Load as needed. MSDN: "The control does not receive Show events if the form is hidden and then shown again, or if the form is minimized and then restored. The control’s window remains on the form during these operations, and its Visible property doesn’t change."

    结束语解决一个.net Winform控件中的VB6控制与电台/选项按钮的问题正在呈现黑如在我对这个问题响应中的一个概述其他地方,而无需帧转换为图片框的建议。

    Wrapping the vb6 controls within a .Net Winform control resolved the issue with Radio/Option buttons being rendered as black as outlined elsewhere in one of my responses to this question without having to convert the frames to Picture boxes as suggested.

    在一个菜单选项中选择XAML代码是动态创建的,并且通过与WindowsFormsHost标签的包装显示的WPF应用程序。再从净winform应用程序动态创建的控制对象被推入WindowsFormsHost标签上的XAML和控制是由哪些火灾VB6 UserControl_Show然后加载和VB6的形式显示在.NET项目可见。

    In the WPF app as a menu choice is selected xaml code is dynamically created and displayed via a wrapper with a WindowsFormsHost tag. A dynamically created control object from the .Net winform app is then pushed into the WindowsFormsHost tag on the xaml and the control is made visible on the .net project which fires vb6 UserControl_Show and then load and display of the vb6 form.

    这篇关于CAN /你怎么主机在C#WPF应用程序的完整VB6的形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆