We are using the following code to use Microsoft Word's spellchecking functionality, but the dialog box for the spell checker does not appear as the top most window. If the calling form is maximized the user does not see the dialog box at all. I have tried all the suggestion I could find on the internet, calling Activate() before calling CheckSpellling, hide all open forms (which I didn't really like as a solution). Nothing seems to work. Someone else suggested to run code in user32.dll to bring the dialog box window to the topmost getting a window handle, but I'm not sure how that would be implemented. Does anyone have this issue or any suggestions? I tried my solutions on the following configs: Vista / Office 2007, Windows 7 / Office 2010.
private void button1_Click(object sender, EventArgs e) { Microsoft.Office.Interop.Word._Application app = new Microsoft.Office.Interop.Word.Application(); int errors = 0; if (textBox1.Text.Length > 0) { app.Visible = false; object template = Missing.Value; object newTemplate = Missing.Value; object documentType = Missing.Value; object visible = false; object optional = null; Microsoft.Office.Interop.Word._Document doc1 = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible); doc1.Words.First.InsertBefore(textBox1.Text); Microsoft.Office.Interop.Word.ProofreadingErrors spellErrorsColl = doc1.SpellingErrors; errors = spellErrorsColl.Count; this.Opacity = 0; doc1.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.Opacity = 1; object first = 0; object last = doc1.Characters.Count - 1; textBox1.Text = doc1.Range(ref first, ref last).Text; } object saveChanges = false; object originalFormat = Missing.Value; object routeDocument = Missing.Value; app.Quit(ref saveChanges, ref originalFormat, ref routeDocument); MessageBox.Show("Check completed!"); this.Activate(); }
Thank you,
Brad