Keep Interop Form to Top of VB6 Application

Go To StackoverFlow.com

1

I'm using the InteropFormsToolkit version 2.1. I'm trying to make sure that when a .NET form loads from an event being thrown on the VB6 form, that the .NET form can stay on top. I've tried many things and can't get anything to work. I've tried everything from z-index, to adding a managed call into User32.dll to push it to the forefront, etc.

Any ideas are appreciated.

2012-04-04 18:01
by Jason N. Gaylord
ShowDialog() or TopMost should work. To get Show(owner) to work so it stays on top you'll need to get a suitable wrapper for the VB6 window. An IWin32Window or NativeWindow. No idea if you can get that out of the toolkit, ought to be possible - Hans Passant 2012-04-04 18:43
ShowDialog does not as events bubble down to VB6 - Jason N. Gaylord 2012-05-07 21:25


1

In vb6 you can use as:

Private Sub Form_Load()
OnTopMe Me, True
End Sub

and following code in module

Declare Function SetWindowPos Lib "User32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cX As Long, ByVal cY As Long, ByVal wFlags As Long) As Long


Public Sub OnTopMe(FormID As Object, onTop As Boolean)
     If onTop = True Then SetWindowPos FormID.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
     If onTop = False Then SetWindowPos FormID.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Sub

I don't know about how to do it in .Net

2012-05-07 15:30
by Vineet1982
So the issue I may run into is that the VB6 app opens a .NET winform using .show. Then, the .NET winform raises an event that bubbles to VB6. The reason for this is that there are several other VB6 "detail" forms that must be shown when choosing buttons, etc from the .NET form. The detail form would need to be on top. When the detail form is closed, that's where the .NET form slips behind (sometimes) the VB6 main form. HTH - Jason N. Gaylord 2012-05-08 15:28
you means that Your VB6 app => Loads .Net Form => Event on .Net Form => Captured in VB6 and show the vb6 form on the top on that event. If I am wrong some where then let me explain with every event as vb6 is event drive - Vineet1982 2012-05-08 17:04
You are correct. So VB6 App => Contains FrmMain.vb (VB6) => Button loads frmOrder (.NET) => Button on frmOrder fires LoadDetailsEvent in VB6 FrmMain => In event, VB6 FrmOrderDetails.vb (VB6) is ShowDialog(). When FrmOrderDetails is closed, frmOrder seems to slip behind FrmMain - Jason N. Gaylord 2012-05-08 19:19
I am taking some assumptions for resolving the issue are: (i) the Form which is to be displayed is unloaded state; (ii) On .net form event you are able to show vb6 form; (iii) Vb6 Form must not be a MDI Child Form, as they can't be show on top;

Create a separate module and paste the second part of above code in it and what ever the form you want to show on top on event of on_load write "OnTopMe Me, True", Me here means the form which you want to show on top and thus change change it which your form name true to show on top and false to not show on to - Vineet1982 2012-05-09 14:11

has your problem resolved or no - Vineet1982 2012-05-10 19:15
No. I've abandoned this project as even the suggestions weren't solving the issue - Jason N. Gaylord 2012-07-20 17:44
Ads