Starts spell checking the given string.

Namespace:  C1.Win.C1Spell
Assembly:  C1.Win.C1Spell.2 (in C1.Win.C1Spell.2.dll)

Syntax

C#
public string CheckString(
	string str,
	BadWordDialogEnum dialog
)
Visual Basic (Declaration)
Public Function CheckString ( _
	str As String, _
	dialog As BadWordDialogEnum _
) As String

Parameters

str
Type: System..::.String
String to check.
dialog
Type: C1.Win.C1Spell..::.BadWordDialogEnum
The BadWordDialogEnum object that represents whether the bad-word dialog will be used and the language that should be used to display it.

Return Value

Checked string.

Remarks

Use the LastSpellError property and the SpellError event to find out the occurred errors.

Examples

The following code uses the CheckString method to build a list of suggestions for misspelled words:

  • Visual Basic
Copy CodeC#
Private Sub C1Spell1_TypingError(ByVal sender As System.Object, ByVal e As C1.Win.C1Spell.TypingErrorEventArgs) Handles C1Spell1.TypingError
    ' use CheckString method to build a list of suggestions
    C1Spell1.CheckString(e.ErrWord, C1.Win.C1Spell.BadWordDialogEnum.NoDialog)

    ' if no suggestions, just quit
    If C1Spell1.Suggestions.Count = 0 Then Exit Sub

    ' now select the word 
    SetSelection(e.SelStart, e.SelLength)

    ' only one suggestion, assume it is the correct word
    ' replace it automatically
    If C1Spell1.Suggestions.Count = 1 Then
        ChangeText(C1Spell1.Suggestions(0))
        Exit Sub
    End If

    ' build the context menu if there are at least two suggestions
    ' and put the suggestion words as the menu texts
    Dim i As Integer
    For i = 1 To 5
        Me.ContextMenuStrip1.MenuItems(i).Visible = False
    Next
        Me.ContextMenuStrip1.MenuItems(0).Text = e.ErrWord & " (not in dictionary)"
    For i = 1 To 5
        If i > 5 Then Exit For
        If C1Spell1.Suggestions.Count < i Then Exit For

        Me.ContextMenuStrip1.MenuItems(i).Text = C1Spell1.Suggestions(i - 1)
        Me.ContextMenuStrip1.MenuItems(i).Visible = True
    Next

    ' Show the context menu at the current caret position
    ' note that the caret position is the screen position and it
    ' should be transferred to the client position for each text box
    Dim pos As Point
    Dim x, y
    x = C1Spell1.CaretPosX
    y = C1Spell1.CaretPosY
    pos = New Point(x, y)

    Select Case C1Spell1.IntegerTag
        Case 1
            pos = TextBox1.PointToClient(pos)
            Me.ContextMenuStrip1.Show(TextBox1, pos)
        Case 2
            pos = TextBox2.PointToClient(pos)
            Me.ContextMenuStrip1.Show(TextBox2, pos)
        Case 3
            pos = TextBox3.PointToClient(pos)
            Me.ContextMenuStrip1.Show(TextBox3, pos)
    End Select
End Sub

' this sub routine will select the error word
Private Sub SetSelection(ByVal start, ByVal length)
    Select Case C1Spell1.IntegerTag
        Case 1
            TextBox1.Select(start, length)
        Case 2
            TextBox2.Select(start, length)
        Case 3
            TextBox3.Select(start, length)
    End Select
End Sub
  • C#
Copy CodeC#
privatevoid c1Spell1_TypingError(object sender, C1.Win.C1Spell.TypingErrorEventArgs e)
{
    // use CheckString method to build a list of suggestions
    c1Spell1.CheckString(e.ErrWord, C1.Win.C1Spell.BadWordDialogEnum.NoDialog);

    // if no suggestions, just quitif ( c1Spell1.Suggestions.Count == 0 )  return;

    // now select the word
    SetSelection(e.SelStart, e.SelLength);

    // only one suggestion, assume it is the correct word// replace it automaticallyif ( c1Spell1.Suggestions.Count == 1 )
    {
        ChangeText(c1Spell1.Suggestions[0]);
        return;
    }

    // build the context menu if there are at least two suggestions// and put the suggestion words as the menu textsint i;
    for (i = 1; i <= 5; i++)
        this.contextMenuStrip1.MenuItems[i].Visible = false;
        this.contextMenuStrip1.MenuItems[0].Text = e.ErrWord + " (not in dictionary)";
    for (i = 1; i <= 5; i++)
        if ( c1Spell1.Suggestions.Count < i ) break;

        this.contextMenuStrip1p.MenuItems[i].Text = c1Spell1.Suggestions[i - 1];
        this.contextMenuStrip1.MenuItems[i].Visible = true;
    }

    // Show the context menu at the current caret position// note that the caret position is the screen position and it// should be transferred to the client position for each text box
    Point pos;
    int x, y;
    x = c1Spell1.CaretPosX;
    y = c1Spell1.CaretPosY;
    pos = new Point(x, y);

    switch   (c1Spell1.IntegerTag)
    {
        case1:
            pos = textBox1.PointToClient(pos);
            this.contextMenuStrip1.Show(TextBox1, pos);
        case2:
            pos = textBox2.PointToClient(pos);
            this.contextMenuStrip1.Show(TextBox2, pos);
        case3:
            pos = textBox3.PointToClient(pos);
            this.contextMenuStrip1.Show(TextBox3, pos);
    }
}

// this sub routine will select the error wordprivatevoid SetSelection( start, length)
{
    switch  (c1Spell1.IntegerTag)
        {
            case1:
                textBox1.Select(start, length);
            case2:
                textBox2.Select(start, length);
            case3:
                textBox3.Select(start, length);
        }
}

For an example using the CheckString method, see Step 3: Provide As-You-Type Spell Checking (Top Panel).

See Also