英文:
Vb. Net - Microsoft Word messages end up under my Form
问题
I'm developing in vb. net applications for Microsoft Word and forms called via a ribbon.
我正在为Microsoft Word开发VB.NET应用程序,通过一个功能区调用表单。
I recall the forms and attribute the value Me.Topmost = true so that my form remains on top of the Word document.
我调用表单并设置Me.Topmost = true以使我的表单保持在Word文档之上。
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.
然而,当Word消息出现时,它们有时会出现在我的表单下面,只有按ESC键,我才能让表单下面的消息消失并重新控制它们。如何解决这个问题?
Thanks and I hope I made myself understood. I'm learning.
谢谢,希望我表达清楚。我正在学习。
Dim Form1 As New Form1
Dim Form1 As New Form1
Form1.Visible = True
Form1.TopMost = true
Form1.Visible = True
Form1.TopMost = true
英文:
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
答案1
得分: 1
你需要设置父窗口句柄(Word 应用程序窗口)以避免这种情况。Window.Hwnd 属性返回一个整数,表示指定窗口的窗口句柄。然后,您可以使用以下代码创建 IWin32Window 接口的一个实例:
using System.Windows.Forms;
NativeWindow nativeWindow = new NativeWindow();
nativeWindow.AssignHandle(ptrWindowHandle);
最后,您需要使用 Form.Show(IWin32Window) 方法来显示您的窗体(将窗体显示给用户,并指定其所有者)。
英文:
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).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论