how to add spell check on a button click in my editor which is in windows form (strictly)
unable to add spell check
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sam HobbsPosted Jan 17, 2015, 3:48 PM
Aisha SrivastavaPosted Jan 16, 2015, 5:44 AM
And do i have to use napespace using system.word ..
Piyush PansuriyaPosted Jan 16, 2015, 1:19 AM
I think this will help you :
#region "Check validity of a single word, enclosed by a txtrange"
private void DOCheck(string word, ref mshtml.IHTMLTxtRange trg)
{
try
{
if (!this.mSpellChecker.CheckSpelling(word))
{
// Word is incorrect?
trg.select();
String []suggs = null; String sReplace = null;
if (this.mValidWords.ContainsKey(word.Trim()))
{
sReplace = (string)this.mValidWords[word.Trim()];
}
else if (this.mSpellChecker.GetSpellingSuggestions(word, ref suggs) )
{
this.Word = word;
this.SetSuggestionsList(suggs);
m_buttonClicked = false;
while (!m_buttonClicked)
{
Application.DoEvents();
System.Threading.Thread.Sleep(100);
}
sReplace = null;
switch (this.mCommand)
{
case ReturnValue.AutoCorrect: break;
case ReturnValue.Cancel :
//try to escape from the loop
trg.moveEnd("textedit",1);
trg.collapse(false);
throw new SpellCheckerException("Operation Cancelled by user.");
case ReturnValue.Change:
sReplace = GetSelectedListValue();
break;
case ReturnValue.ChangeAll:
sReplace = GetSelectedListValue();
this.mValidWords.Add( word.Trim(),sReplace );
break;
case ReturnValue.Ignore : break;
case ReturnValue.IgnoreAll :
this.mSpellChecker.Ignore( word);
break;
case ReturnValue.Undo : break;
}
}
if ( sReplace != null )
{
try
{
if (word.EndsWith(" "))
trg.pasteHTML(sReplace + " ");
else
trg.pasteHTML(sReplace);
}
catch ( Exception ex)
{
Console.WriteLine("SpellChecker, cannot replace word:{0}",ex.Message);
}
}
}
}
catch ( SpellCheckerException ex)
{//user clicked Cancel
throw ex;
}
catch ( Exception ex)
{
Console.WriteLine(ex.Message, word);
throw ex; // rethrow
}
}
#endregion