Step 1: Create a Customized Main Form
In this step, you will create a Main form that you will use to enter words to spell check. To create the Main spell-checking form, complete the following steps:
1. Create a new .NET project.
2. From the Toolbox, double-click the C1Spell icon to add it to the form. The C1Spell component is added to the component tray.
3. Resize the form and set the Form.Text property to MainForm.
4. Add the following basic controls to the form:
• TextBox
• CheckBox
• Two Button controls
5. Set the following properties:
Textbox:
Property |
Setting |
Multiline |
True |
Text |
badd word |
CheckBox:
Property |
Setting |
Name |
cbCheckTyping |
Text |
Check Typing |
Button controls:
Button |
Property |
Setting |
1 |
Name |
btnCheck |
Text |
CheckControl | |
2 |
Name |
btnOptions |
Text |
Options |
These settings illustrate the following form:
To enable spell-checking functionality, you must enter code in the Code designer of the MainForm.
6. To spell check the list items and implement the DialogForm (which you will create in Step 2), double-click the CheckControl button and enter the following code for the btnCheck_Click event handler:
Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
C1Spell1.BadWordDialog = C1.Win.C1Spell.BadWordDialogEnum.NoDialog
C1Spell1.CheckControl(TextBox1)
End Sub
• C#
private void btnCheck_Click(object sender, EventArgs e)
{
c1Spell1.BadWordDialog = C1.Win.C1Spell.BadWordDialogEnum.NoDialog;
c1Spell1.CheckControl(textBox1);
}
7. The following code allows you to check/uncheck the Check Typing checkbox and have a dialog box appear with spelling suggestions or highlight the bad word, respectively. Add the following code:
Private Sub C1Spell1_BadWord(ByVal sender As System.Object, ByVal e As C1.Win.C1Spell.BadWordEventArgs) Handles C1Spell1.BadWord
If Not cbCheckTyping.Checked Then
ShowUIDialog()
End If
End Sub
Private Sub C1Spell1_PopupDialog(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles C1Spell1.PopupDialog
If cbCheckTyping.Checked Then
ShowUIDialog()
End If
End Sub
Private Sub ShowUIDialog()
Dim frm As New DialogForm()
frm.SetSpell(Me.c1Spell1)
frm.ShowDialog()
End Sub
Private Sub cbCheckTyping_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbCheckTyping.CheckedChanged
If cbCheckTyping.Checked Then
C1Spell1.CheckTyping(TextBox1)
Else
C1Spell1.ClearCheckTyping()
End If
End Sub
• C#
private void c1Spell1_BadWord(object sender, C1.Win.C1Spell.BadWordEventArgs e)
{
if (!cbCheckTyping.Checked)
ShowUIDialog();
}
private void c1Spell1_PopupDialog(object sender, EventArgs e)
{
if (cbCheckTyping.Checked)
ShowUIDialog();
}
private void ShowUIDialog()
{
DialogForm frm = new DialogForm();
frm.SetSpell(this.c1Spell1);
frm.ShowDialog();
}
private void cbCheckTyping_CheckedChanged(object sender, EventArgs e)
{
if (cbCheckTyping.Checked)
c1Spell1.CheckTyping(textBox1);
else
c1Spell1.ClearCheckTyping();
}
8. To implement the OptionsForm (which you will create in Step 3), double-click the Options button and enter the following code for the btnOptions_Click event handler:
Private Sub btnOptions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOptions.Click
Dim frm As New OptionsForm()
frm.SetSpell(C1Spell1)
frm.ShowDialog()
End Sub
• C#
private void btnOptions_Click(object sender, EventArgs e)
{
OptionsForm frm = new OptionsForm();
frm.SetSpell(c1Spell1);
frm.ShowDialog();
}
|