Spell checker in textbox

Bageshkumarbagi
Posted by Bageshkumarbagi under C# category on | Points: 40 | Views : 999
First take one text box. on textBox1_Leave

private void textBox1_Leave(object sender, EventArgs e)
{
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
_Document doc;
try
{
// Microsoft.Office.Interop.Word.Document adoc = new Microsoft.Office.Interop.Word.Document();
if (textBox1.Text.Length > 0)
{
app.Visible = false;
// Setting these variables is comparable
// to passing null to the function.
// This is necessary because the C# null
// cannot be passed by reference.
object template = Missing.Value;
object newTemplate = Missing.Value;
object documentType = Missing.Value;
object visible = true;
object optional = Missing.Value;
doc = app.Documents.Add(ref template,
ref newTemplate, ref documentType, ref visible);
doc.Words.First.InsertBefore(textBox1.Text);
Microsoft.Office.Interop.Word.ProofreadingErrors we = doc.SpellingErrors;
iErrorCount = we.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);
if (iErrorCount == 0)
label1.Text = "Spelling OK. No errors corrected ";
else if (iErrorCount == 1)
label1.Text = "Spelling OK. 1 error corrected ";
else
label1.Text = "Spelling OK. " + iErrorCount +
" errors corrected ";
object first = 0;
object last = doc.Characters.Count - 1;
textBox1.Text = doc.Range(ref first, ref last).Text;
object saveChanges = false;
object originalFormat = Missing.Value;
object routeDocument = Missing.Value;
doc.Close(ref saveChanges, ref originalFormat, ref routeDocument);
app.Quit(saveChanges, originalFormat, routeDocument);

doc = null;
app = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();


//doc.Close(ref saveChanges, ref originalFormat, ref routeDocument);
//app.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
}
else
label1.Text = "Textbox is empty";
object saveChangess = false;
object originalFormats = Missing.Value;
object routeDocuments = Missing.Value;
//doc.Close(ref saveOption, ref originalFormat, ref routeDocument);

//app.Quit(saveChanges, originalFormat, routeDocument);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{

object saveChangess = false;
object originalFormats = Missing.Value;
object routeDocuments = Missing.Value;
}
}

Comments or Responses

Posted by: t5j9033387989 on: 12/19/2013 Level:Starter | Status: [Member] | Points: 10
thanks for posting helping me a lot.

Login to post response