Question having problems in codeing a spell-checker

notepadpro

New member
Joined
Apr 22, 2011
Messages
1
Programming Experience
Beginner
hello guys,

sorry if this is a basic question for you guys but iam having trouble in making a spell checker for vb.net richtextbox control.

I have made a form with richtextbox control and a panel control. I have put a listbox control in the panel control and filled with certain words. What iam able to do is whenever i select a word and click a button the panel appears just below the word (using get position from char) and display the choice. What iam not able to do is:

1) Select each word one-by-one whenever i click a button say F1 - I know keypress event but how do i select the words through keypress. I know they are separated by spaces but iam not familiar as to how to take advantage of it. The major problem being that there can be 2-3 words together sometimes colored as red. Eg:

This is nice car color and nice forum too.

What i want is when i press F1 first time "this" is selected, next time "is" is selected and next time "nice car color" is selected. The two things are spaces and red color but i don't get anything from it.


2) Display the panel correctly within the main form's border. Right now when i select the last word of the sentence some part of panel disappears as it hides behind the main form. Eg - only 1/4th appears and rest hides. I can't find a way to limit it from moving when it has reached the main form size. I want to constrain it between top-bottom and left-right border of main form.

I know you guys spent whole day typing code, but it would be really helpful if i could get a small help from you guys with the code part. Or else no problems. :)
 
[Edit]-Saw this post while browsing the forum, related to the richtextbox, check it out, http://www.vbdotnetforums.com/windows-forms/47263-selecting-text-richtextbox-underlined.html


1) I'm not sure if this is what you mean but you could just parse through the words and the colored words you get. for example: RichTextBox1.Rtf.ToString() will return the following from the text example you gave.

VB.NET:
{\rtf1\fbidis\ansi\ansicpg1252\deff0\deflang1033\deflangfe1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Calibri;}}
{\colortbl ;\red255\green0\blue0;}
\viewkind4\uc1\pard\ltrpar\sa200\sl276\slmult1\f0\fs22 This is \cf1 nice car color\cf0  and \cf1 nice forum\cf0  too.\par
}

2) Display the panel correctly within the main form's border. I want to constrain it between top-bottom and left-right border of main form.

i think this is what your talking about? if you want you can do a little math and use something like the following:

basically just calculate how big your panel or whatever control it is that shows up would be, then check to see if that plus its location would go out of bounds or not, and if it does select the appropriate location to put it. Like if the combined width is greater than the form width then set the location of the panel to show up on the left of it, and so forth.

VB.NET:
            Dim xLoc As Integer = (offset.X + location.X + Panel2.Width + (find.Length * RichTextBox1.Font.SizeInPoints))
            Dim yLoc As Integer = (offset.Y + location.Y + RichTextBox1.Font.Height + Panel2.Height)

            If (xLoc > Me.Width) And (yLoc > Me.Height) Then
                showPanelAt(pnLocation.leftTop, find)
            ElseIf (xLoc > Me.Width) Then
                showPanelAt(pnLocation.left, find)

            ElseIf (yLoc > Me.Height) Then
                showPanelAt(pnLocation.top, find)

            Else
                showPanelAt(pnLocation.bottom, find)
            End If

VB.NET:
    Enum pnLocation
        top
        bottom
        left
        right
        leftTop
        rightTop
    End Enum

    Sub showPanelAt(ByVal location As pnLocation, ByVal find As String)
        'get the location of text and textbox
        Dim textBoxOffset As Point = RichTextBox1.Location
        Dim textLocation As Point = RichTextBox1.GetPositionFromCharIndex(RichTextBox1.Text.IndexOf(find))

        'calculate the panels location
        Dim panelLocation As Point

        Select Case location
            Case Is = pnLocation.top
                panelLocation.X = textBoxOffset.X + textLocation.X
                panelLocation.Y = (textBoxOffset.Y + textLocation.Y) - (Panel2.Height)

            Case Is = pnLocation.bottom
                panelLocation.X = textBoxOffset.X + textLocation.X
                panelLocation.Y = textBoxOffset.Y + textLocation.Y + RichTextBox1.Font.Height

            Case Is = pnLocation.right
                panelLocation.X = textBoxOffset.X + textLocation.X + (find.Length * RichTextBox1.Font.SizeInPoints)
                panelLocation.Y = textBoxOffset.Y + textLocation.Y + RichTextBox1.Font.Height

            Case Is = pnLocation.left
                panelLocation.X = textBoxOffset.X + textLocation.X - Panel2.Width
                panelLocation.Y = textBoxOffset.Y + textLocation.Y + RichTextBox1.Font.Height

            Case Is = pnLocation.rightTop
                panelLocation.X = textBoxOffset.X + textLocation.X + (find.Length * RichTextBox1.Font.SizeInPoints)
                panelLocation.Y = (textBoxOffset.Y + textLocation.Y) - (Panel2.Height)

            Case Is = pnLocation.leftTop
                panelLocation.X = textBoxOffset.X + textLocation.X - Panel2.Width
                panelLocation.Y = (textBoxOffset.Y + textLocation.Y) - (Panel2.Height)

        End Select

        Panel2.Visible = True
        Panel2.Location = panelLocation
    End Sub

Hope that helps,

Regards,
-Flippedbeyond
 
Last edited:
Back
Top