| Anyone wishing to use this code in their projects may do so, however are required to leave a post on this page stating that they are using this.
A simple "I am using i00 Spell check in my project" will suffice. |
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 3
rd 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.
Eventually, this project progressed even further into a generic control extension plugin that provides plugins for text box printing, translation, speech recognition and dictation plus more; while also providing a simple method for users to write their own extensions.
Screenshots
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
Support for DataGridViews!
Plugin support ... with Label plugin
Plugin support ... with FastColoredTextBox plugin
Implementation
To implement i00 .NET Spell Check into your project, first either:
- Add the
i00SpellCheck
project to your solution and reference it (recommended)
- Reference the i00SpellCheck.exe file that is output from this project*
- or you can bring all of *.vb files in the "SpellCheck\Spell Check" folder (from the zip) directly into your own project (VB.Net only)*
NOTE: For the methods with the * you will need to also copy the dictionary files to the applications path
Next, simply place this at the very top of your form:
Imports SpellCheck.i00SpellCheck
using i00SpellCheck;
Now you will be able to enable control extensions by going:
Me.EnableControlExtensions()
this.EnableControlExtensions(null);
The above line will enable control extensions on all controls that are supported on the form, and all owned forms that are opened.
Some other examples are below:
ControlExtensions.LoadSingleControlExtension(TextBox1, New TextBoxPrinter.TextBoxPrinter)
TextBox1.EnableSpellCheck()
AddHandler ControlExtensions.ControlExtensionAdding, AddressOf ControlExtensionAdding
TextBox1.EnableSpellCheck()
TextBox1.DisableSpellCheck()
Dim SpellCheckEnabled = TextBox1.IsSpellCheckEnabled()
Dim PrinterExtLoaded = TextBox1.ExtensionCast(Of TextBoxPrinter.TextBoxPrinter)() IsNot Nothing
TextBox1.SpellCheck.Settings.AllowAdditions = True
TextBox1.SpellCheck.Settings.AllowIgnore = True
TextBox1.SpellCheck.Settings.AllowRemovals = True
TextBox1.SpellCheck.Settings.ShowMistakes = True
Dim PrinterExt = TextBox1.ExtensionCast(Of TextBoxPrinter.TextBoxPrinter)()
PrinterExt.Print()
Dim iSpellCheckDialog = TryCast(TextBox1.SpellCheck, i00SpellCheck.SpellCheckControlBase.iSpellCheckDialog)
If iSpellCheckDialog IsNot Nothing Then
iSpellCheckDialog.ShowDialog()
End If
Dim Dictionary = New i00SpellCheck.FlatFileDictionary("c:\Custom.dic")
Dim Dictionary = New i00SpellCheck.FlatFileDictionary("c:\Custom.dic", True)
Dictionary.Add("CustomWord1")
Dictionary.Add("CustomWord2")
Dictionary.Add("CustomWord3")
Dictionary.Save()
TextBox1.SpellCheck.CurrentDictionary = Dictionary
TextBox1.SpellCheck.CurrentDictionary.ShowUIEditor()
TextBox1.SpellCheck.InvalidateAllControlsWithSameDict()
Private Sub ControlExtensionAdding(ByVal sender As Object, ByVal e As ControlExtensionAddingEventArgs)
Dim SpellCheckControlBase = TryCast(e.Extension, SpellCheckControlBase)
If SpellCheckControlBase IsNot Nothing Then
Static SpellCheckSettings As i00SpellCheck.SpellCheckSettings If SpellCheckSettings Is Nothing Then
SpellCheckSettings = New i00SpellCheck.SpellCheckSettings
SpellCheckSettings.AllowAdditions = True SpellCheckSettings.AllowIgnore = True SpellCheckSettings.AllowRemovals = True SpellCheckSettings.AllowInMenuDefs = True SpellCheckSettings.AllowChangeTo = True End If
SpellCheckControlBase.Settings = SpellCheckSettings
End If
End Sub
ControlExtensions.LoadSingleControlExtension(TextBox1, New TextBoxPrinter.TextBoxPrinter());
TextBox1.EnableSpellCheck(null);
ControlExtensions.ControlExtensionAdding += ControlExtensionAdding;
TextBox1.EnableSpellCheck(null);
TextBox1.DisableSpellCheck();
bool SpellCheckEnabled = TextBox1.IsSpellCheckEnabled();
var PrinterExtLoaded = TextBox1.ExtensionCast<textboxprinter.textboxprinter>() != null;
TextBox1.SpellCheck(true, null).Settings.AllowAdditions = true;
TextBox1.SpellCheck(true, null).Settings.AllowIgnore = true;
TextBox1.SpellCheck(true, null).Settings.AllowRemovals = true;
TextBox1.SpellCheck(true, null).Settings.ShowMistakes = true;
object PrinterExt = TextBox1.ExtensionCast<textboxprinter.textboxprinter>();
PrinterExt.Print();
var iSpellCheckDialog = TextBox1.SpellCheck(true,null) as i00SpellCheck.SpellCheckControlBase.iSpellCheckDialog;
if (iSpellCheckDialog != null) {
iSpellCheckDialog.ShowDialog();
}
i00SpellCheck.FlatFileDictionary Dictionary = new i00SpellCheck.FlatFileDictionary("c:\\Custom.dic", false);
i00SpellCheck.FlatFileDictionary Dictionary = new i00SpellCheck.FlatFileDictionary("c:\\Custom.dic", true);
Dictionary.Add("CustomWord1");
Dictionary.Add("CustomWord2");
Dictionary.Add("CustomWord3");
Dictionary.Save(Dictionary.Filename, true);
TextBox1.SpellCheck(true, null).CurrentDictionary = Dictionary;
TextBox1.SpellCheck(true, null).CurrentDictionary.ShowUIEditor();
TextBox1.SpellCheck(true, null).InvalidateAllControlsWithSameDict(true);
static i00SpellCheck.SpellCheckSettings SpellCheckSettings = null;private void ControlExtensionAdding(object sender, i00SpellCheck.MiscControlExtension.ControlExtensionAddingEventArgs e)
{
var SpellCheckControlBase = e.Extension as SpellCheckControlBase;
if (SpellCheckControlBase != null)
{
if (SpellCheckSettings == null)
{
SpellCheckSettings = new i00SpellCheck.SpellCheckSettings();
SpellCheckSettings.AllowAdditions = true; SpellCheckSettings.AllowIgnore = true; SpellCheckSettings.AllowRemovals = true; SpellCheckSettings.AllowInMenuDefs = true; SpellCheckSettings.AllowChangeTo = true; }
SpellCheckControlBase.Settings = SpellCheckSettings;
}
}</textboxprinter.textboxprinter></textboxprinter.textboxprinter>
Even more examples are included in the Test project in the download.
Plugins
Since version 20120618 i00SpellCheck has plugin support.
Plugins in i00SpellCheck allow components to be spell checked by making a dll or exe file that contains a public class that inherits i00SpellCheck.SpellCheckControlBase
.
They automatically get picked up and allow the spellchecking of extra controls, with no reference to the file itself required. However you will need to place them in the applications path.
The use of plugins allow users to enable spellchecking of their controls, without having to change the i00SpellCheck project.
Another use for them could be to allow the programmer to quickly see if they have spelling errors on forms etc. For example placing the LabelPlugin.exe file in an application path (that already uses i00SpellCheck) will cause all labels in the existing project to be spell checked ... with NO code changes! When the developer wants to deploy their application they simply need to remove the LabelPlugin.exe file, and labels will no longer be corrected.
The basic procedures for creating a plugin are as follows:
- Start by creating a new project (class library or exe)
- Reference i00SpellCheck
- Make a class that inherits
i00SpellCheck.SpellCheckControlBase
- Override the ControlType Property to return the type of control that you want your plugin to spell check
- Add your code
For examples on inheriting i00SpellCheck.SpellCheckControlBase check out the examples in the Plugins path in the download.
Projects
The included projects and a brief description of each are as follows:
- i00SpellCheck - Contains the classes for the spellcheck core /
TextBox
and DataGridView
plugins plus the core components required for other plugins to work - Plugins\LabelPlugin - Contains a plugin that checks the spelling of
Labels
- Plugins\OSControlRenderer - Contains aplugin that renders the
TreeView
and ListViews
to the same that they appear in Windows - Plugins\SelectedControlHighlight - Contains a plugin that extends a variety of
Controls
so that they appear to have a "glow" when selected - Plugins\TextBoxPrinter - Contains a plugin that extends
TextBoxBase
to support printing - Plugins\TextBoxSpeechRecognition - Contains a plugin that extends
TextBoxBase
to include support for voice input (double tap F12) and dictation - Plugins\TextBoxTranslator - Contains a plugin that extends
TextBoxBase
to support Google Translation
- Plugins\3rd Party\FastColoredTextBoxPlugin - Contains a plugin that checks the spelling of the FastColoredTextBox control by Pavel Torgashov
- Tests\BasicTest - A test project that contains basic implementation of i00 SpellCheck
- Tests\CSharpTest - A test project demonstrating the use of i00 Spell Check in C#
- *Tests\Test - A test project that contains advanced implementation of i00 SpellCheck and control extensions
- Tests\3rd Party Dictionaries\HanksDictionaryTest - A test project that demonstrates the use of 3rd party spelling engines in i00 Spell Check. Hank's dictionary in this case (by tewuapple (Hank))
- Tests\3rd Party Dictionaries\OpenOfficeHunspellDictionaryTest - A test project that demonstrates the use of 3rd party spelling engines in i00 Spell Check. Hunspell in this case which has support for open office dictionaries
- Tests\3rd Party Dictionaries\WordDictionaryTest - A test project that demonstrates the use of 3rd party spelling engines in i00 Spell Check. Microsoft Word in this case
* = default startup project
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
(Bold items are things that end users will notice)
20140111
i00SpellCheck
- Fixed single line textbox issue where EnableSpellCheck would be required to be needed 2x (found by hoodch)
- Updated the plugin manager to the latest ... now supports paths and shadow copying (this is not implemented in this project)
- Added help button to spell check dialog (for people who don't know about holding F1)
Test
- Made enabled button work for each tab on demo form
TextBoxSpeechRecognition
- Fixed a few issues with the dictation where it would not put in the dictated text
- Enter now commits dictated text
KonamiCode
WebpageImplementation
- Started implementation for a web interface (currently at a very basic stage)
20130521
i00SpellCheck
- Fixed bug that would occur when multiple textboxbases shared a context menu (found by Adviser)
- DataGridView CellStyle no longer has to be set to WrapMode.True for corrections to appear in the DataGridView
- Fixed a possible rendering issue where the error underlines would not be drawn in some instances
- Fixed a possible bug where, on some rare occasions, the spell check dialog would error upon opening (found by TheComputerMan08 (Brent))
- Fixed an issue where words starting with a capital were not getting picked up by the spell check
- Fixed a bug where if selecting a new dictionary with the default ShowUIEditor function the control would not clear old correct words from cache
- Now automatically spell checks controls in SplitContainers (found by cognositivo)
FastColoredTextBoxPlugin
- Added HTML example to FCTB with html color highlighting
- Updated FCTB to latest version
- Fixed an issue with FCTB where when inserting text all of the text would be spellchecked instead of just the visible range, speeding up large copy and pastes
HanksDictionaryTest
- Added another example of using a different dictionary with i00 Spell Check ... Hanks Dictionary (by tewuapple (Hank))
WordDictionaryTest
- Added another example of using a different dictionary with i00 Spell Check ... Word Dictionary
20130114
i00SpellCheck
- Added engine to make more generic control extensions
- Changed the workings of SpellCheckControlBase to use the more generic control extensions
- Default dictionary load is now threadded even when just calling .SpellCheck
- Control extensions can now specify multiple ControlTypes
- Put the TextBoxBase change case feature into its own control extension
- Put the nicer TextBoxBase context menu into its own control extension
- Made the window animations smoother and more stable for F7 etc
- Control extensions can now be dependant on other control extensions (like references but within control extensions)
TextBoxPrinter
- Added TextBoxPrinter plugin
TextBoxSpeechRecognition
- Added buttons to trigger dictate and speech
- Custom Karaoke rendering control added to test form
- Now uses the new, more generic, control extension rather than extending SpellCheckTextBox
- Speech is no longer "broken up" at the end of each line in Windows 8
OSControlRenderer
- Added OSControlRenderer plugin
SelectedControlHighlight
- Added SelectedControlHighlight plugin
TextBoxTranslator
- Added TextBoxTranslator plugin
Test
- Neatened up Draft Plan rendering
20121102
i00SpellCheck
- Made SpellCheckDialog more universal (so it can be used with other controls more easily)
- Fixed a bug when using the SpellCheckDialog to spell check where the textbox would flicker and repaint several times upon confirming the changes
- Added IgnoreWordsInUpperCase setting (requested by TheMperor)
- Added IgnoreWordsWithNumbers setting (requested by TheMperor)
- Fixed a bug that would cause the balloon tooltip to stuffup if it was on a screen to the left of the primary screen, this could cause the spell check dialog to crash
Test
- Added some options to the Performance Monitor window
OpenOfficeHunspellDictionary
- Hunspell now has case error underlineing
- Added Hunspell syninoum lookup to Hunspell test project
TextBoxSpeechRecognition
- Tray icon appears when using speech
- Added a karaoke style content menu item when speaking
- Now when triggering speek or dictate all instances of speech (across all applications that use i00 spell check) are terminated so that you can't get "multiple people" talking at once
20120920
- Added performance counter
- Fixed a bug with the built in dictionary where the dictionary index would be filled up with user words and potentially cause errors, this also has speed up spellchecking a lot
- Fixed an issue with the spell check dialog, if you had alot of data it would "freeze"
20120914
- Added Redo to context menu for rich text boxes
- Changed the way the items are added to the spell check text box content menus to make them more expandable
- TextBoxSpeechRecognition now adds menu items to TextBoxBase context menus
- Added properties to TextBoxSpeechRecognition to adjust various settings
- Fixed a bug that would cause an error when getting sugguestions for a word, where no sugguestsions could be made
20120907
- Removed some redundant stuff from the project
- Added a button to the test form that brings up the dictionary editor
- Changed the way the flat files dictionary index is stored
- Changed the way the flat files dictionary is stored in memory
- Changed the dictionary alot to allow for easy user dictionary creation for inherreted dictionary classes
- Added a C# test project
- Added a test project to demonstrate how people can use other spelling engines in i00 Spell Check. Hunspell in this case which has support for open office dictionaries
20120903
- Added SpellCheckControlAdding event that allows you to pass back e.Cancel = True to prevent the control from being checked
- Fixed a bug that could produce an error if you call .EnableSpellCheck multiple times on several forms (found by rfreedlund)
- Indexed dictionary - added slightly to the initial loading time... but sped up checking significantly (requested by Maverickz)
- Fixed a rare occuring bug where an error would be thrown with the spellcheck cache
- User dictionary file is now separate from the built in dictionary
- Ignored words are now stored in the user dictionary
- Updated the FlatFile dictionary editor to support the new user dictionary
- Added i00Binding List to the project for the FlatFile Dictionary editor... you can remove the reference, if you want, but will first have to remove the dictionary editor if you don't require it (found in i00SpellCheck\Spell Check\Engine\Dictionary\Flat File\Editor)
- Changed the dictionary dramatically to support custom classes to enable the checking of other dictionary formats
- Added a plugin that extends the SpellCheckTextbox, adding voice recognition to it! However Microsoft's inbuilt speech recognition isn't great. Press F12 twice quickly to perform speech recognition
- Made built in plugins more extendable
20120625
- Changed the way the words get added to the dictionary cache (increased spell checking speed)
- Improved the speed of the FastColoredTextBox Plugin
- Made the test project automatically pickup any plugins in the project path and add them to tabs automatically - the references to the plugins are not required, they were added for the LabelPlugin and FastColoredTextBoxPlugin so that they automatically get placed in the same folder when the project is built!
20120622 - FastColoredTextBox
- Changed some internal workings of the spell checker
- Added support for FastColoredTextBox with included plugin!
20120618 - Plugins!
- Added test plugin to project that grants the ability to spell check labels
- Changed the structure / inner workings of the spell check alot / made the spell check more modular and plugins possible!
- Fixed a bug where the settings were not being applied under certain circumstances to spell check controls
- Grid view spell checking now is shown on cells even when their not being edited
20120609 - DataGridView's are go!
- Added support for DataGridViews (requested by in2tech)
- Fixed a bug where the underlines would not draw in the correct positions when word wrapping is disabled
- Fixed a bug where single line TextBoxes would not always show spelling errors
20120608 - Disabling and bug fixes
- Fixed a bug where if you had an apostrophe at the start of a word it would push the underline spacing out (found by jwinney)
- Added ability to disable the spell check on a TextBox (requested by Gabriel X)
- Fixed a bug where the standard TextBox was not refreshing properly since the new rendering method was added
- Fixed bug where if a TextBox contained errors and all text was deleted the underlines would still show (found by jim400)
- Some minor interface changes with splash screen and "alt" for menu
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
Possible Issues
SpellCheckTextBox
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 / 7 to activate Flip3D, it even appears on the same window!
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 the corrections "float" off the form!
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:
DirectCast(TextBox.SpellCheck, SpellCheckTextBox).RenderCompatibility = True
Thanks
A special thanks to Pavel Torgashov for his excellent FastColoredTextBox control. This control is used in the solution to test i00SpellCheck's plugin architecture with 3rd party controls. i00 has not modified this control in any way and is only responsible for integrating the spell checking ability to it via an i00SpellCheck plugin. In no way is this control required for spell checking functions in other projects within the solution.
Thanks for downloading.
Suggestions on possible improvements are much appreciated.