Step 2: Create a Customized Dialog Form
In this step, you will create a Dialog form that includes a list of suggestions for a misspelled word during a spell check. To create the Dialog form, complete the following steps:
1. Create a new Windows form.
• Go to the Solution Explorer and right-click the project.
• Select Add | New Item. The Add New Item window appears.
• Select Windows Form and rename the form DialogForm.
• Click Add.
2. Resize the form.
3. Add the following basic controls to the form:
• One Label control
• One ListBox control
• Five Button controls
4. Set the following properties:
Label control:
Property |
Setting |
Text |
Suggestions: |
ListBox control:
Property |
Setting |
Name |
lbSuggestions |
Button controls:
Button |
Property |
Setting |
1 |
Name |
btnChange |
Text |
Change | |
2 |
Name |
btnIgnore |
Text |
Ignore | |
3 |
Name |
btnChangeAll |
Text |
ChangeAll | |
4 |
Name |
btnIgnoreAll |
Text |
IgnoreAll | |
5 |
Name |
btnCancel |
Text |
Cancel |
These settings illustrate the following form:
To enable spell-checking functionality, you must enter code in the Code designer of the DialogForm.
5. Select View | Code to open the DialogForm Code designer if it is not already open.
6. To declare a private variable name for C1Spell, enter the following code in the declaration section of the DialogForm Code designer:
Private _spell As C1.Win.C1Spell.C1Spell
• C#
private C1.Win.C1Spell.C1Spell _spell;
7. To create a list of suggestions in the list box, add the following code to the DialogForm:
Public Sub SetSpell(spell As C1.Win.C1Spell.C1Spell)
Me._spell = spell
Dim i As Integer
For i = 0 To _spell.Suggestions.Count - 1
Me.lbSuggestions.Items.Add(_spell.Suggestions(i))
Next i
End Sub
• C#
public void SetSpell(C1.Win.C1Spell.C1Spell spell)
{
Self._spell = spell;
for (int i = 0; i < _spell.Suggestions.Count; i++)
this.lbSuggestions.Items.Add(_spell.Suggestions[i]);
}
8. To implement the Change button, enter the following code for the btnChange_Click event handler:
Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click
If lbSuggestions.SelectedIndex >= 0 Then
_spell.CheckWord = lbSuggestions.Items(lbSuggestions.SelectedIndex)
Close()
End If
End Sub
• C#
private void btnChange_Click(object sender, EventArgs e)
{
if (lbSuggestions.SelectedIndex >= 0)
{
_spell.CheckWord = (string)lbSuggestions.Items[lbSuggestions.SelectedIndex];
Close();
}
}
9. To implement the Ignore button, enter the following code for the btnIgnore_Click event handler:
Private Sub btnIgnore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIgnore.Click
_spell.IgnoreWord = True
Close()
End Sub
• C#
private void btnIgnore_Click(object sender, EventArgs e)
{
_spell.IgnoreWord = true;
Close();
}
10. To implement the Cancel button, enter the following code for the btnCancel_Click event handler:
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
_spell.CancelSpelling = True
Close()
End Sub
• C#
private void btnCancel_Click(object sender, EventArgs e)
{
_spell.CancelSpelling = true;
Close();
}
11. To implement the Change All button, enter the following code for the btnChangeAll_Click event handler:
Private Sub btnChangeAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChangeAll.Click
If lbSuggestions.SelectedIndex >= 0 Then
_spell.ChangeAllWords = CStr(lbSuggestions.Items(lbSuggestions.SelectedIndex))
Close()
End If
End Sub
• C#
private void btnChangeAll_Click(object sender, EventArgs e)
{
if (lbSuggestions.SelectedIndex >= 0)
{
_spell.ChangeAllWords = (string)lbSuggestions.Items[lbSuggestions.SelectedIndex];
Close();
}
}
12. To implement the Ignore All button, enter the following code for the btnIgnoreAll_Click event handler:
Private Sub btnIngnoreAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIgnoreAll.Click
_spell.AddIgnoreAll(_spell.CheckWord)
_spell.IgnoreWord = True
Close()
End Sub
• C#
private void btnIngnoreAll_Click(object sender, EventArgs e)
{
_spell.AddIgnoreAll(_spell.CheckWord);
_spell.IgnoreWord = true;
Close();
}
|