Fixing a prompt window over the main window in a windows application using C#

主宰稳场 提交于 2019-12-12 03:43:48

问题


We have included a spell check feature in our windows application and here's the issue we are facing.

Steps in replicating the issue:

  1. Clicked on the spell check feature.
  2. Tabbed to another application before the spell check prompt appeared.
  3. On coming back, the application is unresponsive as the spell check window has gone out of focus.

The only way to access the application after which is to use Alt + Tab, go to the window and close it. My question is how can the prompt window be fixed over the application window that when the application is selected from the Taskbar the application comes with the prompt window? (Like how it happens when I close a Word application, and it prompts me to save and when I tab to another application and back to the word the prompt is still accessible)

How do I make the prompt that comes out of Document.CheckSpelling()- a method that returns void, a modal prompt.

Here's the code:

 Microsoft.Office.Interop.Word.Application app = new     Microsoft.Office.Interop.Word.Application();
 app.Visible = false;

 object template = Missing.Value;
 object newTemplate = Missing.Value;
 object documentType = Missing.Value;
 object visible = false;
 object optional = Missing.Value;

 Microsoft.Office.Interop.Word.Document doc = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);

 doc.Words.First.InsertBefore(s);// s is the string containing the text
 doc.CheckSpelling(ref optional, ref optional, ref optional,
                ref optional, ref optional, ref optional, ref optional,
                ref optional, ref optional, ref optional,
                ref optional, ref optional);//This method gives the prompt window with the suggestions.

回答1:


YOur prompt window must be a child of your application window. If you create a window/ or a message box or something and it does not have a parent window, that's what would happen. FInd the window handle of your app and pass it as parent for your child window/prompt



来源:https://stackoverflow.com/questions/41235668/fixing-a-prompt-window-over-the-main-window-in-a-windows-application-using-c-sha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!