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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Piyush PansuriyaRank #454 · 5.5K reputationPosted Jan 15, 2015, 8:19 PM EST
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
Aisha SrivastavaRank #7,688 · 236 reputationPosted Jan 16, 2015, 12:44 AM EST
And do i have to use napespace using system.word ..
Sam HobbsRank #107 · 20.5K reputationPosted Jan 17, 2015, 10:48 AM EST