Word Spell Check pops up hidden and "freezes" my App
- by Refracted Paladin
I am using Word's Spell Check in my in house WinForm app. My clients are all XP machines with Office 2007 and randomly the spell check suggestion box pops up behind the App and makes everything "appear" frozen as you cannot get at it.
Suggestions? What do other people do to work around this or stop it altogether?
Thanks
Below is my code, for reference, though I am doubtful that this has anything to do with my code but I'll take anything.
public class SpellCheckers
{
public string CheckSpelling(string text)
{
Word.Application app = new Word.Application();
object nullobj = Missing.Value;
object template = Missing.Value;
object newTemplate = Missing.Value;
object documentType = Missing.Value;
object visible = false;
object optional = Missing.Value;
object savechanges = false;
app.ShowMe();
Word._Document doc = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
doc.Words.First.InsertBefore(text);
Word.ProofreadingErrors errors = doc.SpellingErrors;
var ecount = errors.Count;
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);
object first = 0;
object last = doc.Characters.Count - 1;
var results = doc.Range(ref first, ref last).Text;
doc.Close(ref savechanges, ref nullobj, ref nullobj);
app.Quit(ref savechanges, ref nullobj, ref nullobj);
Marshal.ReleaseComObject(doc);
Marshal.ReleaseComObject(app);
Marshal.ReleaseComObject(errors);
return results;
}
}
And I call it from my WinForm app like so --
public static void SpellCheckControl(Control control)
{
if (IsWord2007Available())
{
if (control.HasChildren)
{
foreach (Control ctrl in control.Controls)
{
SpellCheckControl(ctrl);
}
}
if (IsValidSpellCheckControl(control))
{
if (control.Text != String.Empty)
{
control.BackColor = Color.FromArgb(180, 215, 195);
control.Text = Spelling.CheckSpelling(control.Text);
control.Text = control.Text.Replace("\r", "\r\n");
control.ResetBackColor();
}
}
}
}