Results 1 to 27 of 27

Thread: [RESOLVED] Spelling Checking

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    89

    Resolved [RESOLVED] Spelling Checking

    I'm trying to code a spelling checker into VB.NET 2010.
    It'll check the RichTextBoxFindandPrint (my version of RTB) control.
    However the solutions on the internet require Word to be installed.
    Any non-Word ideas?

    PS. I found .NetSpell, how to code it in?
    http://www.codeproject.com/KB/string/netspell.aspx
    Last edited by VOT Productions; Dec 30th, 2010 at 10:05 AM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Spelling Checking

    Having no idea what NetChecker was, I googled it, and found that it is a "NetChecker is a network diagnostic & assistance tool designed to simplify your everyday tasks."

    What does that have to do with spell checking a richtextbox?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    89

    Re: Spelling Checking

    *facepalm*
    It's .NetSpell

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Spelling Checking

    Ok...never heard of that either, but Google did a good job.

    According to this, you don't need any kind of coding.

    http://www.aspnetspell.com/?gclid=CL...FYa7Kgod2zVanQ

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    89

    Re: Spelling Checking

    it said multiline textbox not richtextbox

    and it said ASP.Net Web Applications not VB.Net Desktop Applications
    Last edited by VOT Productions; Dec 29th, 2010 at 12:00 PM.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Spelling Checking

    This is exactly what is says
    Quote Originally Posted by Text From Link I Posted
    No C# or VB.Net coding required. Just drag and drop the SpellTextBox onto the page for a multiline textbox with context menu (as-you-type) spelling in all major browsers. for spelling in in a dialog popup window - just drag a spellbutton onto the page.... by defulat it will automatically detect all checkable fields and spellcheck them.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    89

    Re: Spelling Checking

    Well then I need either the source or a different solution because if I use this I'll lose my other richtextbox which has the extended ability to print and find stuff.

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Spelling Checking

    Quote Originally Posted by VOT Productions View Post
    Well then I need either the source or a different solution because if I use this I'll lose my other richtextbox which has the extended ability to print and find stuff.
    So you tried it with your control and it did not work? Maybe you could extend the control in the same way that you extended the RTB?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9
    Addicted Member
    Join Date
    Feb 2010
    Posts
    197

    Re: Spelling Checking

    Is this:

    http://www.codeproject.com/KB/string/netspell.aspx

    The same .netspell your on about? If so i use this library on my rtb's and i cant praise it enough, no need to have word etc installed, and its easy to code for, ill post up some cod eif this is the same library.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    89

    Re: Spelling Checking

    OK... I'll post my RichTextBoxPrintandFind code tomorrow

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    89

    Re: Spelling Checking

    vb Code:
    1. Option Explicit On
    2.  
    3. Imports System
    4. Imports System.Windows.Forms
    5. Imports System.Drawing
    6. Imports System.Runtime.InteropServices
    7. Imports System.Drawing.Printing
    8.  
    9. Namespace RichTextBoxPrintCtrl
    10.     Public Class RichTextBoxPrintCtrl
    11.         Inherits RichTextBox
    12.         Private Const AnInch As Double = 14.4
    13.         Public Sub FindAndReplace(ByVal FindText As String, ByVal ReplaceText As String)
    14.             Me.Find(FindText)
    15.             If Not Me.SelectionLength = 0 Then
    16.                 Me.SelectedText = ReplaceText
    17.             Else
    18.                 MsgBox("The following specified text was not found: " & FindText)
    19.             End If
    20.         End Sub
    21.         Public Sub FindAndReplace(ByVal FindText As String, ByVal ReplaceText As String, ByVal ReplaceAll As Boolean, _
    22.          ByVal MatchCase As Boolean, ByVal WholeWord As Boolean)
    23.  
    24.             Select Case ReplaceAll
    25.  
    26.                 Case False
    27.                     If MatchCase = True Then
    28.                         If WholeWord = True Then
    29.                             Me.Find(FindText, RichTextBoxFinds.MatchCase Or RichTextBoxFinds.WholeWord)
    30.                         Else
    31.                             Me.Find(FindText, RichTextBoxFinds.MatchCase)
    32.                         End If
    33.                     Else
    34.                         If WholeWord = True Then
    35.                             Me.Find(FindText, RichTextBoxFinds.WholeWord)
    36.                         Else
    37.                             Me.Find(FindText)
    38.                         End If
    39.                     End If
    40.  
    41.                     If Not Me.SelectionLength = 0 Then
    42.                         Me.SelectedText = ReplaceText
    43.                     Else
    44.                         MsgBox("The following specified text was not found: " & FindText)
    45.                     End If
    46.  
    47.  
    48.                 Case True
    49.  
    50.  
    51.                     Dim i As Integer
    52.                     For i = 0 To Me.TextLength 'We know that strings we have to replace < TextLength of RichTextBox
    53.  
    54.  
    55.                         If MatchCase = True Then
    56.                             If WholeWord = True Then
    57.                                 Me.Find(FindText, RichTextBoxFinds.MatchCase Or RichTextBoxFinds.WholeWord)
    58.                             Else
    59.                                 Me.Find(FindText, RichTextBoxFinds.MatchCase)
    60.                             End If
    61.                         Else
    62.                             If WholeWord = True Then
    63.                                 Me.Find(FindText, RichTextBoxFinds.WholeWord)
    64.                             Else
    65.                                 Me.Find(FindText)
    66.                             End If
    67.                         End If
    68.  
    69.  
    70.                         If Not Me.SelectionLength = 0 Then
    71.                             Me.SelectedText = ReplaceText
    72.                         Else
    73.                             MsgBox(i & " occurrence(s) replaced")
    74.                             Exit For
    75.                         End If
    76.                     Next i
    77.  
    78.             End Select
    79.         End Sub
    80.  
    81.  
    82.  
    83.  
    84.         <StructLayout(LayoutKind.Sequential)> _
    85.          Private Structure RECT
    86.             Public Left As Integer
    87.             Public Top As Integer
    88.             Public Right As Integer
    89.             Public Bottom As Integer
    90.         End Structure
    91.  
    92.         <StructLayout(LayoutKind.Sequential)> _
    93.         Private Structure CHARRANGE
    94.             Public cpMin As Integer          ' First character of range (0 for start of doc)
    95.             Public cpMax As Integer          ' Last character of range (-1 for end of doc)
    96.         End Structure
    97.  
    98.         <StructLayout(LayoutKind.Sequential)> _
    99.         Private Structure FORMATRANGE
    100.             Public hdc As IntPtr             ' Actual DC to draw on
    101.             Public hdcTarget As IntPtr       ' Target DC for determining text formatting
    102.             Public rc As Rect                ' Region of the DC to draw to (in twips)
    103.             Public rcPage As Rect            ' Region of the whole DC (page size) (in twips)
    104.             Public chrg As CHARRANGE         ' Range of text to draw (see above declaration)
    105.         End Structure
    106.  
    107.         Private Const WM_USER As Integer = &H400
    108.         Private Const EM_FORMATRANGE As Integer = WM_USER + 57
    109.  
    110.         Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wp As IntPtr, ByVal lp As IntPtr) As IntPtr
    111.  
    112.         ' Render the contents of the RichTextBox for printing
    113.         '   Return the last character printed + 1 (printing start from this point for next page)
    114.         Public Function Print(ByVal charFrom As Integer, ByVal charTo As Integer, ByVal e As PrintPageEventArgs) As Integer
    115.  
    116.             ' Mark starting and ending character
    117.             Dim cRange As CHARRANGE
    118.             cRange.cpMin = charFrom
    119.             cRange.cpMax = charTo
    120.  
    121.             ' Calculate the area to render and print
    122.             Dim rectToPrint As RECT
    123.             rectToPrint.Top = e.MarginBounds.Top * AnInch
    124.             rectToPrint.Bottom = e.MarginBounds.Bottom * AnInch
    125.             rectToPrint.Left = e.MarginBounds.Left * AnInch
    126.             rectToPrint.Right = e.MarginBounds.Right * AnInch
    127.  
    128.             ' Calculate the size of the page
    129.             Dim rectPage As RECT
    130.             rectPage.Top = e.PageBounds.Top * AnInch
    131.             rectPage.Bottom = e.PageBounds.Bottom * AnInch
    132.             rectPage.Left = e.PageBounds.Left * AnInch
    133.             rectPage.Right = e.PageBounds.Right * AnInch
    134.  
    135.             Dim hdc As IntPtr = e.Graphics.GetHdc()
    136.  
    137.             Dim fmtRange As FORMATRANGE
    138.             fmtRange.chrg = cRange                 ' Indicate character from to character to
    139.             fmtRange.hdc = hdc                     ' Use the same DC for measuring and rendering
    140.             fmtRange.hdcTarget = hdc               ' Point at printer hDC
    141.             fmtRange.rc = rectToPrint              ' Indicate the area on page to print
    142.             fmtRange.rcPage = rectPage             ' Indicate whole size of page
    143.  
    144.             Dim res As IntPtr = IntPtr.Zero
    145.  
    146.             Dim wparam As IntPtr = IntPtr.Zero
    147.             wparam = New IntPtr(1)
    148.  
    149.             ' Move the pointer to the FORMATRANGE structure in memory
    150.             Dim lparam As IntPtr = IntPtr.Zero
    151.             lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange))
    152.             Marshal.StructureToPtr(fmtRange, lparam, False)
    153.  
    154.             ' Send the rendered data for printing
    155.             res = SendMessage(Handle, EM_FORMATRANGE, wparam, lparam)
    156.  
    157.             ' Free the block of memory allocated
    158.             Marshal.FreeCoTaskMem(lparam)
    159.  
    160.             ' Release the device context handle obtained by a previous call
    161.             e.Graphics.ReleaseHdc(hdc)
    162.  
    163.             ' Return last + 1 character printer
    164.             Return res.ToInt32()
    165.         End Function
    166.  
    167.         Private Sub InitializeComponent()
    168.             Me.SuspendLayout()
    169.             Me.ResumeLayout(False)
    170.  
    171.         End Sub
    172.     End Class
    173. End Namespace

    Any way to put .netspell inside this code?

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    89

    Re: Spelling Checking

    Please help me!

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    89

    Re: Spelling Checking

    I'll do anything for spell checking in my program!

  14. #14
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Spelling Checking

    Did you read this:

    "Using the Library

    To use the NetSpell Library in your project you simply add a reference to NetSpell.SpellChecker.dll to the project. You can also add the library to the Visual Studio Toolbox to make it easier to interact with the properties. The library is event based so you have to handle the various events. Also, if you set the ShowDialog property to true, the library will use its internal suggestion form to display the suggestion when a MisspelledWord event occurs.

    The following code is a very simple implementation of the NetSpell library..."

    It seems straight forward. Have you downloaded it? Did you add a reference? What have you tried?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    89

    Re: Spelling Checking

    I'm a noob, help me...
    Right, I'm downloading .netSpell
    I got a million files now.
    I dragged it in the toolbox, Spelling and WordDictionary appeared.
    What's next?
    Last edited by VOT Productions; Dec 30th, 2010 at 03:05 PM.

  16. #16
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Spelling Checking

    Do what I would do if I were attempting this, which I have never done, read the directions on the link. C# isn't that far from VB.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    89

    Re: Spelling Checking

    I know only VB

  18. #18
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: Spelling Checking

    There are quite a few free online C# to VB.NET converters out there, like this one, that do a pretty good job.

    Don't expect anybody to simply write out the code for you, because that usually won't happen. Everybody on this forum is a volunteer and generally if they have to spend more than a few minutes to write the code for you, then they won't.

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    89

    Re: Spelling Checking

    Thanks, I'll try it

  20. #20
    Addicted Member
    Join Date
    Feb 2010
    Posts
    197

    Re: Spelling Checking

    Heres how i use this dll, obviously you will have to adapt the code to suit your needs, i have an RTB and a button whcih when clicked performs the spellcheck.

    Heres how the code is:

    vb Code:
    1. Private Sub SpellChecker2_DeletedWord(ByVal sender As Object, ByVal e As NetSpell.SpellChecker.SpellingEventArgs) Handles SpellChecker.DeletedWord
    2.         'save existing selecting
    3.         Dim start As Integer = RichTextBox8.SelectionStart
    4.         Dim length As Integer = RichTextBox8.SelectionLength
    5.  
    6.         'select word for this event
    7.         RichTextBox8.Select(e.TextIndex, e.Word.Length)
    8.  
    9.         'delete word
    10.         RichTextBox8.SelectedText = ""
    11.  
    12.         If ((start + length) > RichTextBox8.Text.Length) Then
    13.             length = 0
    14.         End If
    15.  
    16.         'restore selection
    17.         RichTextBox8.Select(start, length)
    18.  
    19.     End Sub
    20.  
    21.     ' Handles replacing a word from spell checking
    22.     Private Sub SpellChecker2_ReplacedWord(ByVal sender As Object, ByVal e As NetSpell.SpellChecker.ReplaceWordEventArgs) Handles SpellChecker.ReplacedWord
    23.         'save existing selecting
    24.         Dim start As Integer = RichTextBox8.SelectionStart
    25.         Dim length As Integer = RichTextBox8.SelectionLength
    26.  
    27.         'select word for this event
    28.         RichTextBox8.Select(e.TextIndex, e.Word.Length)
    29.  
    30.         'replace word
    31.         RichTextBox8.SelectedText = e.ReplacementWord
    32.  
    33.         If ((start + length) > RichTextBox8.Text.Length) Then
    34.             length = 0
    35.         End If
    36.  
    37.         'restore selection
    38.         RichTextBox8.Select(start, length)
    39.     End Sub

    The above 2 just need placing in and the 'richtextbox8' replacing with your rtb.

    And then on the button used to trigger the spell check this code:

    vb Code:
    1. SpellChecker.Text = RichTextBox8.Text
    2.         SpellChecker.SpellCheck()

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    89

    Re: Spelling Checking

    Reply to post #18

    so I got - line 1 col 10: invalid TypeDecl
    And no source.

    The world is a incompatible place.

  22. #22

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    89

    Re: Spelling Checking

    Quote Originally Posted by DragonRose View Post
    Heres how i use this dll, obviously you will have to adapt the code to suit your needs, i have an RTB and a button whcih when clicked performs the spellcheck.

    Heres how the code is:

    vb Code:
    1. Private Sub SpellChecker2_DeletedWord(ByVal sender As Object, ByVal e As NetSpell.SpellChecker.SpellingEventArgs) Handles SpellChecker.DeletedWord
    2.         'save existing selecting
    3.         Dim start As Integer = RichTextBox8.SelectionStart
    4.         Dim length As Integer = RichTextBox8.SelectionLength
    5.  
    6.         'select word for this event
    7.         RichTextBox8.Select(e.TextIndex, e.Word.Length)
    8.  
    9.         'delete word
    10.         RichTextBox8.SelectedText = ""
    11.  
    12.         If ((start + length) > RichTextBox8.Text.Length) Then
    13.             length = 0
    14.         End If
    15.  
    16.         'restore selection
    17.         RichTextBox8.Select(start, length)
    18.  
    19.     End Sub
    20.  
    21.     ' Handles replacing a word from spell checking
    22.     Private Sub SpellChecker2_ReplacedWord(ByVal sender As Object, ByVal e As NetSpell.SpellChecker.ReplaceWordEventArgs) Handles SpellChecker.ReplacedWord
    23.         'save existing selecting
    24.         Dim start As Integer = RichTextBox8.SelectionStart
    25.         Dim length As Integer = RichTextBox8.SelectionLength
    26.  
    27.         'select word for this event
    28.         RichTextBox8.Select(e.TextIndex, e.Word.Length)
    29.  
    30.         'replace word
    31.         RichTextBox8.SelectedText = e.ReplacementWord
    32.  
    33.         If ((start + length) > RichTextBox8.Text.Length) Then
    34.             length = 0
    35.         End If
    36.  
    37.         'restore selection
    38.         RichTextBox8.Select(start, length)
    39.     End Sub

    The above 2 just need placing in and the 'richtextbox8' replacing with your rtb.

    And then on the button used to trigger the spell check this code:

    vb Code:
    1. SpellChecker.Text = RichTextBox8.Text
    2.         SpellChecker.SpellCheck()
    We are getting close! SpellChecker is not declared. It may be inaccessible due to its protection level.

    Did you mean something else?

    I've got:
    Spelling1
    WordDictionary1

  23. #23

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    89

    Re: Spelling Checking

    vb Code:
    1. Private Sub SpellChecker1_DeletedWord(ByVal sender As Object, ByVal e As NetSpell.SpellChecker.SpellingEventArgs) Handles SpellChecker1.DeletedWord
    2.         'save existing selecting
    3.         Dim start As Integer = Rich.SelectionStart
    4.         Dim length As Integer = Rich.SelectionLength
    5.  
    6.         'select word for this event
    7.         Rich.Select(e.TextIndex, e.Word.Length)
    8.  
    9.         'delete word
    10.         Rich.SelectedText = ""
    11.  
    12.         If ((start + length) > Rich.Text.Length) Then
    13.             length = 0
    14.         End If
    15.  
    16.         'restore selection
    17.         Rich.Select(start, length)
    18.  
    19.     End Sub
    20.  
    21.     ' Handles replacing a word from spell checking
    22.     Private Sub SpellChecker1_ReplacedWord(ByVal sender As Object, ByVal e As NetSpell.SpellChecker.ReplaceWordEventArgs) Handles SpellChecker1.ReplacedWord
    23.         'save existing selecting
    24.         Dim start As Integer = Rich.SelectionStart
    25.         Dim length As Integer = Rich.SelectionLength
    26.  
    27.         'select word for this event
    28.         Rich.Select(e.TextIndex, e.Word.Length)
    29.  
    30.         'replace word
    31.         Rich.SelectedText = e.ReplacementWord
    32.  
    33.         If ((start + length) > Rich.Text.Length) Then
    34.             length = 0
    35.         End If
    36.  
    37.         'restore selection
    38.         Rich.Select(start, length)
    39.     End Sub
    40.  
    41.     Private Sub Button1_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    42.         SpellChecker1.Text = Rich.Text
    43.         SpellChecker1.SpellCheck()
    44.     End Sub

    That's my current code, no en-GB.dic found.

  24. #24

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    89

    Re: Spelling Checking

    How does

    vb Code:
    1. internal System.Windows.Forms.RichTextBox Document;
    2. internal NetSpell.SpellChecker.Spelling SpellChecker;
    translate to VB.NET?

  25. #25
    Addicted Member
    Join Date
    Feb 2010
    Posts
    197

    Re: Spelling Checking

    That's my current code, no en-GB.dic found.
    You need to put the en-gb.dic inside your debug/projects exe folder.

  26. #26

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    89

    Re: Spelling Checking

    My face and my palm

  27. #27

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    89

    Re: Spelling Checking

    It worked!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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