Click here to Skip to main content
Licence Ms-PL
First Posted 8 Oct 2011
Views 18,211
Downloads 0
Bookmarked 69 times

i00 VB.NET Spell Check - No 3rd Party Components Required!

By | 3 Feb 2012 | Article
Simple to use, open source Spell Checker for .NET
Prize winner in Competition "Best VB.NET article of October 2011"

Introduction

I wanted a spell check that I could use in .NET, so like most people would have done, I Googled. After many hours of fruitless searching, I decided to make my own; sure there are plenty of spell checkers out there, but I didn't want one that relied on 3rd party components such as Word or require Internet connectivity to work. Introducing i00 .NET Spell Check, the first and only VB.NET Spell Check written completely in VB! Not only that, it is also open source, and easy to use.

Screen Shots

Spell check with definitions

In-menu word definitions and Change to...

Adding words to dictionary

Custom content menus

Crossword generator

Options

Owner draw and RTB support

Spell check dialog

Using the Code

To implement i00 .NET Spell Check into your project, first either:

  • Reference the i00SpellCheck.exe file that is output from this project
  • Add the i00SpellCheck project to your solution and reference it
  • or you can bring all of *.vb files in the "SpellCheck\Spell Check" folder (from the zip) directly into your own project

Next, simply place this at the very top of your form:

* the code below may change if you used option 3 to "Imports YourProject.i00SpellCheck"):

Imports SpellCheck.i00SpellCheck

Now you will be able to enable spell check. The above line will enable spell checking on all multiline textboxes on your form, and all owned forms that are opened.

Some other examples are below:

'''enable the spell check
''this will enable the spell check on ALL TEXT FIELDS ON THIS form 
''AND ALL TEXT FIELDS ON ALL OWNED FORMS AS THEY OPEN automatically :)
''... but only for multi line Rich/Text Boxes
Me.EnableSpellCheck()
''To enable spell check on single line textboxes you will need to call:
TextBox.SpellCheck()

''if you wanted to pass in options you can do so by going:
Dim SpellCheckSettings As New i00SpellCheck.SpellCheckTextBox.SpellCheckSettings
SpellCheckSettings.DoSubforms = True     'Specifies if owned forms should be 
                    'automatically spell checked
SpellCheckSettings.AllowAdditions = True     'Specifies if you want to allow the user 
                    'to add words to the dictionary
SpellCheckSettings.AllowIgnore = True     'Specifies if you want to allow the user 
                    'ignore words
SpellCheckSettings.AllowRemovals = True     'Specifies if you want to allow users 
                    'to delete words from the dictionary
SpellCheckSettings.AllowInMenuDefs = True     'Specifies if the in menu definitions 
                    'should be shown for correctly spelled words
SpellCheckSettings.AllowChangeTo = True     'Specifies if "Change to..." (to change 
                    'to a synonym) should be shown in the menu 
                    'for correctly spelled words
'SpellCheckSettings...etc
Me.EnableSpellCheck(SpellCheckSettings)


''You can also enable spell checking on one text field:
TextBox1.SpellCheck()
''Note that the above is NOT threaded - so if you fire it from the interface 
''it can "freeze" for a second if the dictionary is not yet loaded 
''(unless you load the dictionary in a separate thread).

''To change options on an individual text box:
TextBox1.SpellCheck.Settings.AllowAdditions = True
TextBox1.SpellCheck.Settings.AllowIgnore = True
TextBox1.SpellCheck.Settings.AllowRemovals = True
TextBox1.SpellCheck.Settings.ShowMistakes = True
''etc

''To show a spellcheck dialog for an individual text box:
TextBox1.SpellCheck.ShowDialog()

''To load a custom dictionary from a saved file:
Dim Dictionary = New i00SpellCheck.SpellCheckTextBox.Dictionary("c:\Custom.dic")

''To create a new blank dictionary and save it as a file
Dim Dictionary = New i00SpellCheck.SpellCheckTextBox.Dictionary("c:\Custom.dic", True)
Dictionary.Add("CustomWord1")
Dictionary.Add("CustomWord2")
Dictionary.Add("CustomWord3")
Dictionary.Save()

''To Load a custom dictionary for an individual text box:
TextBox1.SpellCheck.CurrentDictionary = Dictionary

''To Open the dictionary editor for a dictionary associated with a text box:
Using DictionaryEditor As New DictionaryEditor
    TextBox1.SpellCheck.CurrentDictionary = _

    DictionaryEditor.ShowDialog(RichTextBox1.SpellCheck.CurrentDictionary)
    TextBox1.SpellCheck.InvalidateAllTextBoxesWithSameDict()
End Using

Even more examples are included in the Test project in the download.

Points of Interest

The words that get checked are added to a dictionary cache to speed up checking - the smaller cache is checked first. If the word is not found in the cache, then it checks the main dictionary.

I use fields (public variables) instead of properties for some basic classes, as they are about 2x faster than properties.

Downloads

Total Downloads:

Downloads per day:

Change Log

20120203

  • Tooltips now have image support and images for some definitions
  • Fixed tool tip rendering issues
  • You can now press F3 to change case of the selected text (requested by rykk)
  • Made "-" be classified as a word break char
  • Fixed an error that would re-paint the textbox errors 2x
  • Disabled Cut/Copy/Paste options in menu if not on an STA thread as this would error

20120102 - Happy New Year!

  • Modified definitions to lookup from file dynamically rather than being loaded into memory to reduce RAM usage ~56MB saved!
  • Changed settings so that all the spellcheck settings are in a single class
  • Cleaned up the SpellCheckTextBox class and subclasses to make settings easily editable with a property grid
  • Added property grid to the test project
  • Added a dictionary editor
  • Added a "bare-bones" test project to the solution, to make it simpler for users to see how easy it can be to use i00 .NET Spell Check in your projects!
  • Changed the render method to eliminate redraw flicker, added a setting to revert to the old render method "RenderCompatibility"

20111202 - Now with dialog!

  • Cleaned up some stuff ... moved HTML formatted tooltip + HTML ToolStripItem into their own controls
  • Made the Text ToolStripSeperator look and function better
  • Made the right click menu items portable so that they can be added to any menu for other things - not so tightly bound to the text box
  • Implementing a spell check dialog for F7 style spell checking (select text box and press F7!... can also be called with: TextBoxName.SpellCheck.ShowDialog())

20111109 - In-menu definitions, synonyms and fixes!

  • Changed tooltip definitions to match more words from their word base, e.g. "suggestions" matches "suggestion" for definition since no definition is matched explicitly for suggestions and states that it is plural in the tip
  • Tooltip for definitions is now owner draw so that it appears a little nicer
  • Fixed a case matching bug where "This" would suggest "this" rather than "This" (requested by TxDeadhead)
  • Words like "Chris's" now suggest "Chris'" instead of "Chris's"
  • Words that end in an ' no longer appear as being misspelled
  • Made the context menu position itself a little better if near the bottom or right sides of a screen
  • Fixed a bug where, if you press the context menu button on the keyboard multiple times, the menu would add multiple of the same corrections to the context menu
  • Sped up loading of dictionary file
  • Fixed a bug in the definition file - all adjectives and adverbs were mixed up (i.e., all adjectives were listed as adverbs, and all adverbs were listed as adjectives)!
  • Various speed optimizations in finding word suggestions, to lookup misspelled word "suggestions" used to take ~250ms, now down to ~150ms
  • Improved suggestion lookup now adds higher weight to words with extra duplicates or missing duplicates (such as "running", "running" > "running")
  • Added in-context-menu definitions for correctly spelled words (requested by Dean)
  • Words with interesting cases (such as SUpport, SupporT etc) now get picked up (requested by TxDeadhead)
  • Now doesn't fall over if the dictionary, definitions or synonyms files have been removed - just removes functionality for that bit
  • Added synonyms; "Change to..." menu item (requested by NtEditor)

20111106 - Been busy!

  • Various speed optimizations
  • Dictionary is now stored as a Flat File for portability
  • Added owner draw support for spelling errors
  • Added the ability to customize colors for highlighting misspelled words
  • Added some examples of how to customize the appearance of the spell check
  • Word definitions added for spelling suggestions ... so if you are unsure of the correct spelling out of the suggestions, you can pick the correct one from the definition
  • The right click menu in .NET comes up from the middle of a text box when pressing the context menu button on the keyboard - It has now been modified to pop-out from the carets location
  • Cross word generator - plan to make solver later too!
  • Support added for Rich Text Boxes
  • Added Suggestion Lookup Example

20111011 - Some fun extras

  • Added anagram lookup
  • Added Scrabble helper

20111008 - Minor changes

  • Fixed a bug where the text box underlines would not always draw initially until the textbox was scrolled or had some text changed
  • Cleaned up the interface to made it look more professional

20111006

  • Initial Release

Possible Issues

Since the Textbox has no way to really draw on it "nicely", I used to capture the WM_PAINT of the control and then draw on the textbox graphics that was set by going Graphics.FromHwnd... this seemed to work well but produced a slight flicker that I thought was undesirable...

As of version 20120102, the render method now uses layered windows (by default), this basically means that all of the underlines that appear to be drawn on the control are actually drawn on another window over the top of the control ...

So how does this affect the user? Well in most cases it doesn't, the form is click-through and only the drawings are visible not the form itself. In fact if you press start + tab in Windows Vista+, it even appears on the same window (as shown below)!

As I said above "in most cases"...

MIDI forms I haven't tested, but am quite sure that they won't work using the new render method.

Overlapping controls appear as follows:

And if the textbox is off the form it appears like:

So in cases such as the above, you will have to go back to the older "compatible" rending, this can be done in these cases by going:

TextBox.SpellCheck.Settings.RenderCompatibility = True

Thanks

Thanks for downloading.

Suggestions on possible improvements are much appreciated.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

About the Author

i00

Software Developer (Senior)
i00 Productions
Australia Australia

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionCan't download PinmemberMember 88337770:44 17 Apr '12  
AnswerRe: Can't download Pinmemberi0014:08 19 Apr '12  
QuestionHow to disable? PinmemberGabriel X21:45 11 Apr '12  
AnswerRe: How to disable? Pinmemberi0014:07 19 Apr '12  
GeneralRe: How to disable? PinmemberGabriel X17:45 19 Apr '12  
QuestionNice Product PinmemberSanta's Little Helper23:23 26 Mar '12  
AnswerRe: Nice Product Pinmemberi0023:37 26 Mar '12  
BugSerialization Exception Pinmemberkals8419:28 28 Feb '12  
GeneralRe: Serialization Exception Pinmemberi001:32 29 Feb '12  
GeneralMy vote of 5 Pinmembermanoj kumar choubey21:22 23 Feb '12  
QuestionI cannot download PinmemberAlan11999:20 14 Feb '12  
AnswerRe: I cannot download Pinmemberi002:07 21 Feb '12  
QuestionReference .exe in 2010 Pinmemberileaney10:15 9 Feb '12  
AnswerRe: Reference .exe in 2010 Pinmemberi0016:59 9 Feb '12  
GeneralRe: Reference .exe in 2010 Pinmemberileaney3:54 10 Feb '12  
GeneralRe: Reference .exe in 2010 Pinmemberi0012:35 12 Feb '12  
QuestionNot useable PinmemberJustJimBean6:26 7 Feb '12  
AnswerRe: Not useable Pinmemberi0022:50 7 Feb '12  
GeneralMy vote of 5 PinmemberHoyaSaxa936:30 3 Feb '12  
GeneralMy vote of 5 PinmemberAlessandro Bernardi5:27 19 Nov '11  
Questionnice PinmemberCIDev8:10 16 Nov '11  
QuestionDanish dictionary PinmemberMember 454455818:25 14 Nov '11  
AnswerRe: Danish dictionary [modified] Pinmemberi004:41 15 Nov '11  
GeneralRe: Danish dictionary PinmemberMember 454455818:06 15 Nov '11  
GeneralRe: Danish dictionary Pinmemberi0021:28 15 Nov '11  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 3 Feb 2012
Article Copyright 2011 by i00
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid