I Spoke too soon about not having adverse affects. I later found that
Word would open as small as possible in the upper left corner after
running doing this. Below is a function that will avoid the flicker
and reset the window position when completed. You might note that I had
problems with Word adding a Carriage Return to the end of the text that
I later stripped off if it was unwanted.
Hope this helps somebody,
Scott #s
using Word = Microsoft.Office.Interop.Word;
using System.Runtime.InteropServices;
....
public String CheckSpelling(String Txt) {
int iTop;
int iLeft;
int iHeight;
int iWidth;
object oMissing = System.Reflection.Missing.Value;
object oFalse = false;
object oTrue = true;
String CheckedTxt = ""; Default for Error Conditions
try {
Word.ApplicationClass wrdApp = new Word.ApplicationClass();
wrdApp.Visible = false;
iTop = wrdApp.Top;
iLeft = wrdApp.Left;
iHeight = wrdApp.Height;
iWidth = wrdApp.Width;
wrdApp.Move(-100,-100);
wrdApp.Resize(1,1);
Word.Document wrdDoc = wrdApp.Documents.Add(ref oMissing, ref
oMissing, ref oMissing, ref oTrue);
wrdDoc.Content.Text = Txt;
wrdDoc.CheckSpelling(ref oMissing,ref oMissing,ref oMissing,ref
oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref
oMissing,ref oMissing,ref oMissing,ref oMissing);
CheckedTxt = wrdDoc.Content.Text;
wrdApp.Visible = false;
wrdApp.Resize(iWidth, iHeight);
wrdApp.Move(iLeft,iTop);
wrdDoc.Saved = true;
wrdDoc.Close(ref oFalse, ref oMissing,ref oMissing);
wrdApp.Quit(ref oFalse, ref oMissing, ref oMissing);
Marshal.ReleaseComObject(wrdApp);
}
catch (Exception Ex) {
MessageBox.Show(Ex.Message);
}
return CheckedTxt;
}
Sc***********@hq.doe.gov wrote:
You probably found a solution by now, so I'll post this for future
readers...
I found that you can set the App Window size and location without any
adverse affects.
// After creating oWord below, add ...
oWord.Visisble = false;
oWord.Top = -1;
oWord.Left = -1;
oWord.Width = 1;
oWord.Height = 1;
This places the App Window off the screen and elimantes the flash
when the spellcheck is completed.
Hope this helps somebody.
Scott #s
Vish wrote: Hello,
I am passing a string to a spell checking function which
performs spell check using word objects. It works fine but even though i have said
oWord.Visible = false;
the word application opens for a moment and closes ,which makes my winform application look bad. Is there any way to supress that.
The C# function i wrote is below.
private String SpellCheck(String str)
{
try
{
object oMissing = System.Reflection.Missing.Value;
String retVal = "";
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = false;
oDoc = oWord.Documents.Add(ref oMissing, ref
oMissing, ref oMissing, ref oMissing);
oDoc.Content.Text = str;
oDoc.CheckGrammar();
oDoc.Content.Copy();
retVal =
Clipboard.GetDataObject().GetData(DataFormats.Text ).ToString();
oDoc.Saved = true;
oDoc.Close(ref oMissing, ref oMissing, ref
oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref
oMissing);
return retVal;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + " : " + ex.Source + "
: " + ex.StackTrace);
return "Fatal Error";
}
}