Results 1 to 40 of 283

Thread: 20130521 - i00 Spell Check and Control Extensions -No Third Party Components Required

Threaded View

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Lightbulb i00 Spell Check and Control Extensions - No Third Party Components Required

    Code Project Prize winner in Competition "Best VB.NET article of October 2011"

    Download
    Anyone wishing to use this code in their projects may do so, however are required to leave a post on this thread stating that they are using this.
    A simple "I am using i00 Spell check in my project" will suffice.


    DO NOT MIRROR
    DO NOT LINK DIRECTLY TO THIS FILE - LINK TO THIS POST INSTEAD
    DO NOT RE-DISTRIBUTE THIS SOURCE CODE PARTLY OR IN ITS ENTIRETY

    Latest Version now hosted on Code Project:

    Go here to download!

    Total Downloads:

    Downloads per day:


    About

    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.

    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.

    Donations
    rykk - $30
    Member 2262881 (POSabilities Inc.) - $100

    Donate Here - and be sure to put "i00 Spell Check", your user name (or other alias), and if you want the amount disclosed in the description field

    Users
    Users have been moved to their own post since the post size had been reached

    Click here for users

    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


    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*

    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:
    * the code below may change if you used option 3 to "Imports YourProject.i00SpellCheck")
    vb Code:
    1. Imports i00SpellCheck

    Now you will be able to enable spell checking by placing the following in your form load event:
    vb Code:
    1. Me.EnableControlExtensions()
    The above line will enable control extensions on all controls that are supported on the form, and all owned forms that are opened.

    Other examples are below:
    vb Code:
    1. 'To load a single control extension on a control call:
    2. ControlExtensions.LoadSingleControlExtension(TextBox1, New TextBoxPrinter.TextBoxPrinter)
    3.  
    4. 'To enable spell check on single line textboxes you will need to call:
    5. TextBox1.EnableSpellCheck()
    6.  
    7. 'If you wanted to pass in options you can do so by handling the ControlExtensionAdding event PRIOR to calling EnableControlExtensions:
    8. AddHandler ControlExtensions.ControlExtensionAdding, AddressOf ControlExtensionAdding
    9. 'Also refer to the commented ControlExtensionAdding Sub in this form for more info
    10.  
    11. 'You can also enable spell checking on an individual Control (if supported):
    12. TextBox1.EnableSpellCheck()
    13.  
    14. 'To disable the spell check on a Control:
    15. TextBox1.DisableSpellCheck()
    16.  
    17. 'To see if the spell check is enabled on a Control:
    18. Dim SpellCheckEnabled = TextBox1.IsSpellCheckEnabled()
    19. 'To see if another control extension is loaded (in this case call see if the TextBoxPrinter Extension is loaded on TextBox1):
    20. Dim PrinterExtLoaded = TextBox1.ExtensionCast(Of TextBoxPrinter.TextBoxPrinter)() IsNot Nothing
    21.  
    22. 'To change spelling options on an individual Control:
    23. TextBox1.SpellCheck.Settings.AllowAdditions = True
    24. TextBox1.SpellCheck.Settings.AllowIgnore = True
    25. TextBox1.SpellCheck.Settings.AllowRemovals = True
    26. TextBox1.SpellCheck.Settings.ShowMistakes = True
    27. 'etc
    28.  
    29. 'To set control extension options / call methods from control extensions (in this case call Print() from TextBox1):
    30. Dim PrinterExt = TextBox1.ExtensionCast(Of TextBoxPrinter.TextBoxPrinter)()
    31. PrinterExt.Print()
    32.  
    33. 'To show a spellcheck dialog for an individual Control:
    34. Dim iSpellCheckDialog = TryCast(TextBox1.SpellCheck, i00SpellCheck.SpellCheckControlBase.iSpellCheckDialog)
    35. If iSpellCheckDialog IsNot Nothing Then
    36.     iSpellCheckDialog.ShowDialog()
    37. End If
    38.  
    39. 'To load a custom dictionary from a saved file:
    40. Dim Dictionary = New i00SpellCheck.FlatFileDictionary("c:\Custom.dic")
    41.  
    42. 'To create a new blank dictionary and save it as a file
    43. Dim Dictionary = New i00SpellCheck.FlatFileDictionary("c:\Custom.dic", True)
    44. Dictionary.Add("CustomWord1")
    45. Dictionary.Add("CustomWord2")
    46. Dictionary.Add("CustomWord3")
    47. Dictionary.Save()
    48.  
    49. 'To Load a custom dictionary for an individual Control:
    50. TextBox1.SpellCheck.CurrentDictionary = Dictionary
    51.  
    52. 'To Open the dictionary editor for a dictionary associated with a Control:
    53. 'NOTE: this should only be done after the dictionary has loaded (Control.SpellCheck.CurrentDictionary.Loading = False)
    54. TextBox1.SpellCheck.CurrentDictionary.ShowUIEditor()
    55.  
    56. 'Repaint all of the controls that use the same dictionary...
    57. TextBox1.SpellCheck.InvalidateAllControlsWithSameDict()
    58.  
    59.  
    60.  
    61.  
    62. ''This is used to setup spell check settings when the spell check extension is loaded:
    63. Private Sub ControlExtensionAdding(ByVal sender As Object, ByVal e As ControlExtensionAddingEventArgs)
    64.     Dim SpellCheckControlBase = TryCast(e.Extension, SpellCheckControlBase)
    65.     If SpellCheckControlBase IsNot Nothing Then
    66.         Static SpellCheckSettings As i00SpellCheck.SpellCheckSettings 'Static for settings to be shared amongst all controls, use dim for control specific settings...
    67.         If SpellCheckSettings Is Nothing Then
    68.             SpellCheckSettings = New i00SpellCheck.SpellCheckSettings
    69.             SpellCheckSettings.AllowAdditions = True 'Specifies if you want to allow the user to add words to the dictionary
    70.             SpellCheckSettings.AllowIgnore = True 'Specifies if you want to allow the user ignore words
    71.             SpellCheckSettings.AllowRemovals = True 'Specifies if you want to allow users to delete words from the dictionary
    72.             SpellCheckSettings.AllowInMenuDefs = True 'Specifies if the in menu definitions should be shown for correctly spelled words
    73.             SpellCheckSettings.AllowChangeTo = True 'Specifies if "Change to..." (to change to a synonym) should be shown in the menu for correctly spelled words
    74.         End If
    75.         SpellCheckControlBase.Settings = SpellCheckSettings
    76.     End If
    77. End Sub

    Even more examples are included in the Test projects included 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.

    Version Changes
    Version changes have been moved to their own post since the post size had been reached

    Click here for version changes

    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 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 appear to "Float" outside 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... Also please provide feedback, rate this thread and say thanks if this helped you

    Suggestions on possible improvements are much appreciated

    Also I extend a special thanks to the users who thanked / rated this post.

    Thanks again
    Kris
    Last edited by i00; Jan 16th, 2014 at 07:48 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width