-1

I'm developing in vb. net applications for Microsoft Word and forms called via a ribbon. I recall the forms and attribute the value Me.Topmost = true so that my form remains on top of the Word document. However, when Word messages appear they can sometimes end up under my form, and only by pressing ESC can I make the messages under the form disappear and regain control of them. How can I work around this problem? Thanks and I hope I made myself understood. I'm learning.

Dim Form1 As New Form1 Form1.Visible = True Form1.TopMost = true

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Luca
  • 1
  • 2

1 Answers1

1

You need to set the parent window handle (the Word application window) for your custom form to avoid such cases. The Window.Hwnd property returns an integer that indicates the window handle of the specified window. Then you can use the following code to create an instance of the IWin32Window interface:

using System.Windows.Forms;

NativeWindow nativeWindow = new NativeWindow();
nativeWindow.AssignHandle(ptrWindowHandle);

Finally, you need to use the Form.Show(IWin32Window) method to display your form (which shows the form with the specified owner to the user).

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • I understand your explanation, but in practice it is difficult for me to apply. I will try to inform myself well, the road is the one you told me. I thank you. – Luca May 18 '23 at 16:22