Can / how do you post the full VB6 form in a WPF application in C #?

I'm currently exploring the possibility of porting some older VB6 applications to WPF using C #. The plan in the first stage is to transfer several key forms, and not in all applications. The theoretical goal is to open a VB6 form in some container in WPF through an ActiveX DLL.

Is it possible? I tried to take a look at Interop and did not seem to find a convincing example of how to make it work with anything except Win32 controls, and not from the full form. I have full access to the old VB6 code and can be modified in any case.

The following screenshot of the main WPF application will serve as a shell / container:

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

The current VB6 maintenance screen, which will be loaded in the white space section on the right side of the previous screen.

+6
c # vb6 interop wpf vb6-migration
source share
5 answers

I managed to complete the task with the following steps:

  • The new VB6 Active X Control Project has been created. The entire contents of the controls and VB6 form code are copied and pasted into the new control. There are several elements that you need to handle when switching to a control:

    • you lose the ability to display the form title in the previous way. You can work it with alternative controls (label / borderlesstextbox, etc.) that perform the same functionality if necessary. This was not a priority, since each screen was hosted in a browser, like the tab system in our new .Net.

    • All mouse pointer links should vary from Me.Mousepointer to Screen.mousepointer

    • You cannot use Me.Hide and need alternative events to hide the .Net container.

    • Any links to Me. [All] needs to be removed or replaced with UserControl. [all] if applicable.

    • If you use any functions that reference a [yourcontrol] .Contianer.Property to forms, they must be changed to execute a loop through UserControl.Controls instead of the Container collection is not valid for ActiveX vb6 controls

    • All non-modal forms / dialogs should be removed from the project as there is now no Hwnd in WPF. You get the error message β€œModal forms cannot be displayed on this host from an ActiveX DLL, ActiveX Control or Property page 'application. In our case, we had a simple splash screen that would be displayed when certain long processes / reports displayed on the report user that works.

  • I was not able to directly add the VB6 control via interop to the WPF project. Since the new .Net project "Windows Form Library" was created. Link to VB6 OCX has been added to the project. Then the VB6 controls were added to the .Net toolbar by right-clicking β†’ Add Item and specifying a com link to the VX6 control ocx. The .Net control was then used to host / service the VB6 Control.

  • To map the host form to VB6 and force it to activate the necessary initialization functions, the VX6 OCX controls were installed by default using the Visible.False method, so they were initially added to .Net OCX as invisible controls. If necessary, the VB6 control is set to visible = True, which fires the UserControl_Show () event. All code previously in Form_Load () has been ported to this event. The show event was the easiest way to access 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 window remains on the form during these operations, and its Visible property does not change."

  • The wrap around the vb6 controls in the .Net Winform control eliminates the problem by using the Radio / Option buttons that appear as black, as indicated elsewhere in one of my answers to this question, without having to convert frames to Images windows, as suggested

  • In the WPF application, the xaml code is dynamically created and displayed through the shell with the WindowsFormsHost tag as the menu selection. The dynamically created control object from the .Net winform application is then placed in the WindowsFormsHost tag on xaml, and the control becomes visible in the .net project, which launches vb6 UserControl_Show, and then loads and displays the vb6 form.

+11
source share

I think you will need to extract the contents of the VB6 form into an ActiveX control. You can then open it in your ActiveX DLL and place it in a WPF form. I doubt that you can place the VB6 form in any other way.

+3
source share

Can I upload this VB6 form to another VB6 form? I suggest you get started first.

+1
source share

There is no reliable way to set the parent of a VB6 form. You can always hack it or use a simple ActiveX control (UserControl in VB6) as a user interface container instead of VB6 forms.

0
source share

I found a way to do what was needed in WinForms, not WPF at the moment. http://www.codeproject.com/KB/vb-interop/VB6formsinNET.aspx I believe that if I can make it work 100%, I can transfer it to WPF or the worst case if it is placed in a WPF form WinForm element in WPF form ( UGLY ).

In any case, I'm a little closer, but I have a very strange problem with some controls that also draw a screen. The Radio / Option buttons are displayed as solid black:

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

I tried to explicitly change the background color of the controls from the keypad to a fixed color, and it still does. I assume this is a separation problem, with the option buttons being within the frame. I worked a bit on how to proceed without massive refinement of the contents of VB6 to change the parameter buttons to checkboxes. This is a powerful application, and there are more than 600 button control buttons in the application that I definitely don't want to have.

EDIT: I was able to confirm that it has something to do with bundle options in the Frame control. If you pull it into the basic form, the problem does not occur: http://www.evocommand.com/junk_delete_me/optionbuttons2.png

0
source share

All Articles