Home   Free Applications   Code Snippets   Fun Stuff 
 
 You are here: Home > Free Applications > NetSpell > Discussion Forum
Register   Login  

 
Site Navigation


Print Print this page
Email E-mail this page
Bookmark Add to Favorites

  Discussion Forum

Author Thread: How can you tell when spell check is finished
?
How can you tell when spell check is finished
Posted: Monday, February 27, 2006 11:27 PM (EST)
I need to spell check several text fields on a form.  Is there a way to tell when the spell check is finished on one field so that I can start spell checking on the next field?


Comments:

Author Thread:
timparr
How can you tell when spell check is finished
Posted: Friday, May 19, 2006 7:59 AM (EST)

I attached a handler to the lostfocus event of the form that the spelling control exposes:

(Public Section)

Private Shared WithEvents mChecker As NetSpell.SpellChecker.Spelling

Private Shared mTB As TextBox

Private Shared mFinished As Boolean

 

Private Shared Sub Init()

mChecker = New Spelling

addHandler  mChecker.SuggestionForm.LostFocus, AddressOf FormLostFocus

End Sub

 

Private Shared Sub FormLostFocus(ByVal sender As Object, ByVal e As System.EventArgs)

mFinished = True

End Sub

 

In a spellcheck routine I then set mFinished to false, call the spellcheck and wait for mFinished to become true.

 

I can post my complete code if you like - email me.

ronks
How can you tell when spell check is finished
Posted: Monday, August 21, 2006 11:04 PM (EST)
I'd be interested to see the complete code, here or in e-mail. In particular, how you wait for mFinished; all I can think of is a DoEvents loop in VB.

ronks
How can you tell when spell check is finished
Posted: Tuesday, August 22, 2006 5:32 PM (EST)
I wanted to follow up on this. I tried timparr's excellent suggestion, and while it didn't work for me out of the box it gave me the hint I needed to accomplish the job - almost. But I may have found a better way, at least for my purposes. To oversimplify a little, I have a form with a user-entry text box and two command buttons, Spell-Check and Save. Clicking on Spell-Check simply invokes the spell-checker in the Click event, nothing more, and works fine. But Save is deigned to invoke the spelling checker, wait till it's done, then save the text box contents to a disk file. The problem with that was that the spell checker was invoked and control returned immediately to the Save-click event handler, which proceeded to save the unmodified text to disk; you could correct the spelling afterwards, but that was too late. Modifying a Boolean switch in the spell-checker form's LostFocus event handler didn't work for me because the form instantly loses focus when it returns control to the calling routine. But setting a pending-save switch in the calling routine, then testing it in the lost-focus event handler, and saving the text and clearing the switch, seemed to do the trick. Except that for some reason when the user clicks "Cancel" on the suggestion form before finishing, the lost-focus event was not triggered; neither was form-closing, form-closed, or any other event I could think of. So I tried something more drastic: I looked at the NetSpell source. Lines 405-407 of SuggestionForm.cs read //display form if (!this.Visible) this.Show(); this.Activate(); I changed this.Show(); to this.ShowDialog(); to make the suggestion window modal, so it won't surrender control until it completes or is canceled, and I think that did the trick. I haven't tested every possible combination, but so far so good.

MRJ
How can you tell when spell check is finished
Posted: Thursday, August 24, 2006 3:25 PM (EST)
Did you find doing this prevented the Suggestion for from showing a result? When I tried it I had no words selected when I run a spell check. I'm not sure if this is caused some changes I found posted in the Code Project Articles comments (http://www.codeproject.com/csharp/NetSpell.asp). The changes include beginning able to all Spell check on multiple controls and hides the suggestion form when it loses form. I'm writing a Windows application and I wanted to have a spell check on the close before saving the data. So I added a Property Modal Suggestion Form to the SpellChecker, and added code to only 'showdialog' when the property is true. But the Suggestion box didn't show the first word. To handle that issue I added a call to SpellCheck on the activation of the form.

ronks
How can you tell when spell check is finished
Posted: Tuesday, January 23, 2007 5:23 PM (EST)
The visible-changed event for the suggestion form seems to be a more reliable way to tell when spell-check is either completed or canceled. Yes, merely changing Show to ShowModal wasn't enough; I just posted today in another thread what seems to be required to get it to work for me.

kalzone
How can you tell when spell check is finished
Posted: Sunday, March 11, 2007 9:39 PM (EST)

I took the approach of extending the TextBox class.  This allowed me to create a context menu as part of the control.  This will let the user right click and chose to Spell check a single textbox.  I also added an F7 spellcheck feature for the form where the user can press F7, then the application will loop through each textbox and call the Check Spelling function.

Here is a sample of what I did.  This worked for my needs anyway.

 

public class TextBox : System.Windows.Forms.TextBox

{

private NetSpell.SpellChecker.Spelling spelling;

private NetSpell.SpellChecker.Dictionary.WordDictionary wordDictionary;

//Context Menu

private System.Windows.Forms.ContextMenu c_ctxmTextBox = new System.Windows.Forms.ContextMenu();

...

public TextBox()

{

//This calls the loadMenu function which will define the context menu to include the Spell Check option

this.loadMenu();

}

///

/// Spell check this text box

///

public void CheckSpelling()

{

try

{

//for performance purposes, do not initialize SpellNet unless it is requested.

if (wordDictionary == null)

{

this.wordDictionary = new NetSpell.SpellChecker.Dictionary.WordDictionary();

this.wordDictionary.DictionaryFile = "en-US.txt";

}

if (spelling == null)

{

this.spelling = new NetSpell.SpellChecker.Spelling();

this.spelling.Dictionary = this.wordDictionary;

this.spelling.ReplacedWord += new NetSpell.SpellChecker.Spelling.ReplacedWordEventHandler(this.spelling_ReplacedWord);

this.spelling.DeletedWord += new NetSpell.SpellChecker.Spelling.DeletedWordEventHandler(this.spelling_DeletedWord);

this.spelling.AlertComplete = false;

}

this.spelling.Text = this.Text;

spelling.SpellCheck()

}

catch(Exception ex)

{

System.Windows.Forms.MessageBox.Show(ex.Message);

}

}

///

/// Delete was hit in SpellNet so remove word from textbox

///

///

///

private void spelling_DeletedWord(object sender, NetSpell.SpellChecker.SpellingEventArgs e)

{

...

}

///

/// Replace word with word from NetSpell

///

///

///

private void spelling_ReplacedWord(object sender, NetSpell.SpellChecker.ReplaceWordEventArgs e)

{

...

}



Top