473,386 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

C# WinForm Spell Checking

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";
}

}
Nov 16 '05 #1
3 3985
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";
}

}


Nov 16 '05 #2
Or you could just use a custom spell checker component such as
SharpSpell, which doesn't require MS Word to be installed and has many
other benefits.

We're using it from ASP.NET and are very pleased with it, but it was
designed primarily for WinForms.

It even has the squiggly underline real-time spell-check (spell as you
type mode), you can find it here:
http://www.tachyon-labs.com/sharpspell/

Nov 16 '05 #3
Scott,

Thanks for sharing your code. The spellchecking works great but it seems
that when dragging word's spellchecking window over my winform application,
my window will not repaint itself. Do anyone have the same problem? I have
used almost the same code in a vb6 application which doesn't have this
problem.

Words spell checker is useless for me as it is now because of this. You can
never read what is underneath it's window.

Any ideas?
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Pater Maximus | last post by:
I want to use the MS Word spell checker from my Python program. I check the spelling a word at a time. It works fine for English but I can not force it to use French when I am using that language....
84
by: Andy Glew | last post by:
I am in search of any rigourous, scientific, academic or industrial studies comparing naming conventions in C++ or similar languages such as Ada: Specifically, are names formed with...
1
by: Lloyd Dupont | last post by:
I see that outlook express has some spell checking capacity. so I though maybe there is a spell checking feature available in windows. the only thing I found out requires word2003, which is to big...
12
by: Ryan | last post by:
Is there anyway to enable spell-checking for user input in a Text Box? Either auto spell-check or create a spell-check button. Using VB 2005.
6
by: Neil | last post by:
Is there way to have control over the MS-Access spell checking (besides just launching it)? We want to tell it to check all records, but skip certain fields (or, alternatively, ONLY check certain...
5
by: Dean Slindee | last post by:
Anybody got any helpful suggestions on how to implement spell checking in a textbox. Perhaps solutions using Microsoft Word spell checker as a called routine? What has worked for you? Thanks,...
22
by: SmokeWilliams | last post by:
Hi, I am working on a Spell checker for my richtext editor. I cannot use any open source, and must develop everything myself. I need a RegExp pattern to split text into a word array. I have...
1
by: SpaceMarine | last post by:
Hello, I am trying to quickly find a simple, inexpensive, spell checking component for a .NET v1.1 WinForms app. We do not need an entire suite of components at this time since the app is...
4
by: BillE | last post by:
I have found articles on line about using word interop for spell checking with visual studio applications. Most of the articles are several years old, though - VS2003, maybe 2005. I couldn't...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.