|
-
Dec 29th, 2010, 08:55 AM
#1
Thread Starter
Lively Member
[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.
-
Dec 29th, 2010, 11:42 AM
#2
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?
-
Dec 29th, 2010, 11:44 AM
#3
Thread Starter
Lively Member
Re: Spelling Checking
*facepalm*
It's .NetSpell
-
Dec 29th, 2010, 11:53 AM
#4
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
-
Dec 29th, 2010, 11:56 AM
#5
Thread Starter
Lively Member
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.
-
Dec 29th, 2010, 12:02 PM
#6
Re: Spelling Checking
This is exactly what is says
 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.
-
Dec 29th, 2010, 12:11 PM
#7
Thread Starter
Lively Member
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.
-
Dec 29th, 2010, 01:28 PM
#8
Re: Spelling Checking
 Originally Posted by VOT Productions
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?
-
Dec 29th, 2010, 03:08 PM
#9
Addicted Member
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.
-
Dec 29th, 2010, 06:00 PM
#10
Thread Starter
Lively Member
Re: Spelling Checking
OK... I'll post my RichTextBoxPrintandFind code tomorrow
-
Dec 30th, 2010, 09:47 AM
#11
Thread Starter
Lively Member
Re: Spelling Checking
vb Code:
Option Explicit On Imports System Imports System.Windows.Forms Imports System.Drawing Imports System.Runtime.InteropServices Imports System.Drawing.Printing Namespace RichTextBoxPrintCtrl Public Class RichTextBoxPrintCtrl Inherits RichTextBox Private Const AnInch As Double = 14.4 Public Sub FindAndReplace(ByVal FindText As String, ByVal ReplaceText As String) Me.Find(FindText) If Not Me.SelectionLength = 0 Then Me.SelectedText = ReplaceText Else MsgBox("The following specified text was not found: " & FindText) End If End Sub Public Sub FindAndReplace(ByVal FindText As String, ByVal ReplaceText As String, ByVal ReplaceAll As Boolean, _ ByVal MatchCase As Boolean, ByVal WholeWord As Boolean) Select Case ReplaceAll Case False If MatchCase = True Then If WholeWord = True Then Me.Find(FindText, RichTextBoxFinds.MatchCase Or RichTextBoxFinds.WholeWord) Else Me.Find(FindText, RichTextBoxFinds.MatchCase) End If Else If WholeWord = True Then Me.Find(FindText, RichTextBoxFinds.WholeWord) Else Me.Find(FindText) End If End If If Not Me.SelectionLength = 0 Then Me.SelectedText = ReplaceText Else MsgBox("The following specified text was not found: " & FindText) End If Case True Dim i As Integer For i = 0 To Me.TextLength 'We know that strings we have to replace < TextLength of RichTextBox If MatchCase = True Then If WholeWord = True Then Me.Find(FindText, RichTextBoxFinds.MatchCase Or RichTextBoxFinds.WholeWord) Else Me.Find(FindText, RichTextBoxFinds.MatchCase) End If Else If WholeWord = True Then Me.Find(FindText, RichTextBoxFinds.WholeWord) Else Me.Find(FindText) End If End If If Not Me.SelectionLength = 0 Then Me.SelectedText = ReplaceText Else MsgBox(i & " occurrence(s) replaced") Exit For End If Next i End Select End Sub <StructLayout(LayoutKind.Sequential)> _ Private Structure RECT Public Left As Integer Public Top As Integer Public Right As Integer Public Bottom As Integer End Structure <StructLayout(LayoutKind.Sequential)> _ Private Structure CHARRANGE Public cpMin As Integer ' First character of range (0 for start of doc) Public cpMax As Integer ' Last character of range (-1 for end of doc) End Structure <StructLayout(LayoutKind.Sequential)> _ Private Structure FORMATRANGE Public hdc As IntPtr ' Actual DC to draw on Public hdcTarget As IntPtr ' Target DC for determining text formatting Public rc As Rect ' Region of the DC to draw to (in twips) Public rcPage As Rect ' Region of the whole DC (page size) (in twips) Public chrg As CHARRANGE ' Range of text to draw (see above declaration) End Structure Private Const WM_USER As Integer = &H400 Private Const EM_FORMATRANGE As Integer = WM_USER + 57 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 ' Render the contents of the RichTextBox for printing ' Return the last character printed + 1 (printing start from this point for next page) Public Function Print(ByVal charFrom As Integer, ByVal charTo As Integer, ByVal e As PrintPageEventArgs) As Integer ' Mark starting and ending character Dim cRange As CHARRANGE cRange.cpMin = charFrom cRange.cpMax = charTo ' Calculate the area to render and print Dim rectToPrint As RECT rectToPrint.Top = e.MarginBounds.Top * AnInch rectToPrint.Bottom = e.MarginBounds.Bottom * AnInch rectToPrint.Left = e.MarginBounds.Left * AnInch rectToPrint.Right = e.MarginBounds.Right * AnInch ' Calculate the size of the page Dim rectPage As RECT rectPage.Top = e.PageBounds.Top * AnInch rectPage.Bottom = e.PageBounds.Bottom * AnInch rectPage.Left = e.PageBounds.Left * AnInch rectPage.Right = e.PageBounds.Right * AnInch Dim hdc As IntPtr = e.Graphics.GetHdc() Dim fmtRange As FORMATRANGE fmtRange.chrg = cRange ' Indicate character from to character to fmtRange.hdc = hdc ' Use the same DC for measuring and rendering fmtRange.hdcTarget = hdc ' Point at printer hDC fmtRange.rc = rectToPrint ' Indicate the area on page to print fmtRange.rcPage = rectPage ' Indicate whole size of page Dim res As IntPtr = IntPtr.Zero Dim wparam As IntPtr = IntPtr.Zero wparam = New IntPtr(1) ' Move the pointer to the FORMATRANGE structure in memory Dim lparam As IntPtr = IntPtr.Zero lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange)) Marshal.StructureToPtr(fmtRange, lparam, False) ' Send the rendered data for printing res = SendMessage(Handle, EM_FORMATRANGE, wparam, lparam) ' Free the block of memory allocated Marshal.FreeCoTaskMem(lparam) ' Release the device context handle obtained by a previous call e.Graphics.ReleaseHdc(hdc) ' Return last + 1 character printer Return res.ToInt32() End Function Private Sub InitializeComponent() Me.SuspendLayout() Me.ResumeLayout(False) End Sub End Class End Namespace
Any way to put .netspell inside this code?
-
Dec 30th, 2010, 10:06 AM
#12
Thread Starter
Lively Member
-
Dec 30th, 2010, 02:39 PM
#13
Thread Starter
Lively Member
Re: Spelling Checking
I'll do anything for spell checking in my program!
-
Dec 30th, 2010, 02:53 PM
#14
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?
-
Dec 30th, 2010, 02:57 PM
#15
Thread Starter
Lively Member
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.
-
Dec 30th, 2010, 03:13 PM
#16
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.
-
Dec 30th, 2010, 03:15 PM
#17
Thread Starter
Lively Member
-
Dec 30th, 2010, 04:02 PM
#18
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.
-
Dec 30th, 2010, 04:13 PM
#19
Thread Starter
Lively Member
-
Dec 30th, 2010, 04:16 PM
#20
Addicted Member
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:
Private Sub SpellChecker2_DeletedWord(ByVal sender As Object, ByVal e As NetSpell.SpellChecker.SpellingEventArgs) Handles SpellChecker.DeletedWord
'save existing selecting
Dim start As Integer = RichTextBox8.SelectionStart
Dim length As Integer = RichTextBox8.SelectionLength
'select word for this event
RichTextBox8.Select(e.TextIndex, e.Word.Length)
'delete word
RichTextBox8.SelectedText = ""
If ((start + length) > RichTextBox8.Text.Length) Then
length = 0
End If
'restore selection
RichTextBox8.Select(start, length)
End Sub
' Handles replacing a word from spell checking
Private Sub SpellChecker2_ReplacedWord(ByVal sender As Object, ByVal e As NetSpell.SpellChecker.ReplaceWordEventArgs) Handles SpellChecker.ReplacedWord
'save existing selecting
Dim start As Integer = RichTextBox8.SelectionStart
Dim length As Integer = RichTextBox8.SelectionLength
'select word for this event
RichTextBox8.Select(e.TextIndex, e.Word.Length)
'replace word
RichTextBox8.SelectedText = e.ReplacementWord
If ((start + length) > RichTextBox8.Text.Length) Then
length = 0
End If
'restore selection
RichTextBox8.Select(start, length)
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:
SpellChecker.Text = RichTextBox8.Text
SpellChecker.SpellCheck()
-
Dec 30th, 2010, 04:16 PM
#21
Thread Starter
Lively Member
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.
-
Dec 30th, 2010, 04:24 PM
#22
Thread Starter
Lively Member
Re: Spelling Checking
 Originally Posted by DragonRose
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:
Private Sub SpellChecker2_DeletedWord(ByVal sender As Object, ByVal e As NetSpell.SpellChecker.SpellingEventArgs) Handles SpellChecker.DeletedWord 'save existing selecting Dim start As Integer = RichTextBox8.SelectionStart Dim length As Integer = RichTextBox8.SelectionLength 'select word for this event RichTextBox8.Select(e.TextIndex, e.Word.Length) 'delete word RichTextBox8.SelectedText = "" If ((start + length) > RichTextBox8.Text.Length) Then length = 0 End If 'restore selection RichTextBox8.Select(start, length) End Sub ' Handles replacing a word from spell checking Private Sub SpellChecker2_ReplacedWord(ByVal sender As Object, ByVal e As NetSpell.SpellChecker.ReplaceWordEventArgs) Handles SpellChecker.ReplacedWord 'save existing selecting Dim start As Integer = RichTextBox8.SelectionStart Dim length As Integer = RichTextBox8.SelectionLength 'select word for this event RichTextBox8.Select(e.TextIndex, e.Word.Length) 'replace word RichTextBox8.SelectedText = e.ReplacementWord If ((start + length) > RichTextBox8.Text.Length) Then length = 0 End If 'restore selection RichTextBox8.Select(start, length) 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:
SpellChecker.Text = RichTextBox8.Text 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
-
Dec 30th, 2010, 04:41 PM
#23
Thread Starter
Lively Member
Re: Spelling Checking
vb Code:
Private Sub SpellChecker1_DeletedWord(ByVal sender As Object, ByVal e As NetSpell.SpellChecker.SpellingEventArgs) Handles SpellChecker1.DeletedWord 'save existing selecting Dim start As Integer = Rich.SelectionStart Dim length As Integer = Rich.SelectionLength 'select word for this event Rich.Select(e.TextIndex, e.Word.Length) 'delete word Rich.SelectedText = "" If ((start + length) > Rich.Text.Length) Then length = 0 End If 'restore selection Rich.Select(start, length) End Sub ' Handles replacing a word from spell checking Private Sub SpellChecker1_ReplacedWord(ByVal sender As Object, ByVal e As NetSpell.SpellChecker.ReplaceWordEventArgs) Handles SpellChecker1.ReplacedWord 'save existing selecting Dim start As Integer = Rich.SelectionStart Dim length As Integer = Rich.SelectionLength 'select word for this event Rich.Select(e.TextIndex, e.Word.Length) 'replace word Rich.SelectedText = e.ReplacementWord If ((start + length) > Rich.Text.Length) Then length = 0 End If 'restore selection Rich.Select(start, length) End Sub Private Sub Button1_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click SpellChecker1.Text = Rich.Text SpellChecker1.SpellCheck() End Sub
That's my current code, no en-GB.dic found.
-
Dec 30th, 2010, 04:47 PM
#24
Thread Starter
Lively Member
Re: Spelling Checking
How does
vb Code:
internal System.Windows.Forms.RichTextBox Document; internal NetSpell.SpellChecker.Spelling SpellChecker;
translate to VB.NET?
-
Dec 30th, 2010, 04:51 PM
#25
Addicted Member
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.
-
Dec 30th, 2010, 04:53 PM
#26
Thread Starter
Lively Member
-
Dec 30th, 2010, 04:59 PM
#27
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|