layout | title | description | platform | control | documentation |
---|---|---|---|---|---|
post |
Getting Started with Windows Forms Spell Checker control | Syncfusion |
Learn here about getting started with Syncfusion Windows Forms Spell Checker (SpellCheckerAdv) control, its elements and more details. |
WindowsForms |
SpellCheckerAdv |
ug |
This section describes how to add a SpellCheckerAdv control in a Windows Forms application and overview of its basic functionalities.
Refer control dependencies section to get the list of assemblies or NuGet package needs to be added as reference to use the control in any application.
Please find more details regarding how to install the nuget packages in windows form application in the below link:
You can create the Windows Forms application with SpellCheckerAdv control as follows:
- Creating project
- Add control via designer
- Add control manually using Code
- Configuring SpellCheckerAdv into RichTextBox control
- Applying Dictionary
- Applying Custom Dictionary
- Configuring VisualStyle
Create a new Windows Forms project in the Visual Studio to display the SpellCheckerAdv with basic information.
SpellCheckerAdv control can be added to the application by dragging it from the toolbox and dropping it in a designer view. The following required assembly references will be added automatically:
- Syncfusion.Grid.Base.dll
- Syncfusion.Grid.Windows.dll
- Syncfusion.Shared.Base.dll
- Syncfusion.Shared.Windows.dll
- Syncfusion.SpellChecker.Base.dll
- Syncfusion.Tools.Base.dll
- Syncfusion.Tools.Windows.dll
To add control manually in C#, follow the given steps:
Step 1 : Add the following required assembly references to the project:
- Syncfusion.Tools.Base.dll
- Syncfusion.Tools.Windows.dll
- Syncfusion.Shared.Base.dll
- Syncfusion.Shared.Windows.dll
- Syncfusion.SpellChecker.Base.dll
- Syncfusion.Grid.Base.dll
- Syncfusion.Grid.Windows.dll
Step 2 : Include the namespaces Syncfusion.Windows.Forms.Tools.
{% tabs %}
{% highlight C# %}
using Syncfusion.Windows.Forms.Tools;
{% endhighlight %}
{% highlight VB %}
Imports Syncfusion.Windows.Forms.Tools
{% endhighlight %}
{% endtabs %}
Step 3 : Create SpellCheckerAdv
control instance.
{% tabs %}
{% highlight C# %}
SpellCheckerAdv spellCheckerAdv1 = new SpellCheckerAdv();
{% endhighlight %}
{% highlight VB %}
Dim spellCheckerAdv1 As SpellCheckerAdv = New SpellCheckerAdv
{% endhighlight %}
{% endtabs %}
Step 1 : Create a class implementing ISpellCheckerAdvEditorTools interface as shown below.
{% tabs %}
{% highlight C# %}
class TextBoxSpellEditor : ISpellCheckerAdvEditorTools { ///
public string CurrentWord { get; set; }
/// <summary>
/// Gets or sets the Text to be spell checked by the <see cref="SpellCheckerAdv"/>
/// </summary>
public string Text
{
get
{
return textBox.Text;
}
set
{
textBox.Text = value;
}
}
/// <summary>
/// Gets or sets the Control whose Text is to be spell checked.
/// </summary>
public Control ControlToCheck
{
get
{
return textBox;
}
set
{
textBox = value as TextBoxBase;
}
}
/// <summary>
/// Selects the word specified by the index.
/// </summary>
/// <param name="selectionStart">Zero based index of the word on the Text.</param>
/// <param name="selectionLength">length of the word to be selected.</param>
public void SelectText(int selectionStart, int selectionLength)
{
textBox.Select(selectionStart, selectionLength);
}
}
{% endhighlight %}
{% highlight VB %}
class TextBoxSpellEditor Implements ISpellCheckerAdvEditorTools '''
{% endhighlight %}
{% endtabs %}
Step 2 - Create instances RichTextBox
(Editor Control to be spell checked) and Button
and add it to the form.
{% tabs %}
{% highlight C# %}
RichTextBox richTextBox1 = new RichTextBox(); Button button1 = new Button();
this.richTextBox1.Text = resources.GetString("richTextBox1.Text"); this.button1.Text="Spell Check";
this.Controls.Add(this.button1); this.Controls.Add(this.richTextBox1);
{% endhighlight %}
{% highlight VB %}
Dim richTextBox1 As RichTextBox = New RichTextBox Dim button1 As Button = New Button
Me.richTextBox1.Text = resources.GetString("richTextBox1.Text") Me.button1.Text="Spell Check"
Me.Controls.Add(Me.button1) Me.Controls.Add(Me.richTextBox1)
{% endhighlight %}
{% endtabs %}
Step 3 - Create an instance of the TextBoxSpellEditor
class by having RichTextBox
as its Control and it to SpellCheckerAdv
using PerformSpellCheckForControl method.
{% tabs %}
{% highlight C# %}
TextBoxSpellEditor TextEditor = new TextBoxSpellEditor(this.richTextBox1);
this.spellCheckerAdv1.PerformSpellCheckForControl(TextEditor);
{% endhighlight %}
{% highlight VB %}
Dim TextEditor As New TextBoxSpellEditor(Me.richTextBox1)
Me.spellCheckerAdv1.PerformSpellCheckForControl(TextEditor)
{% endhighlight %}
{% endtabs %}
Step 4 - Finally trigger SpellCheckerAdv
through an event such as Click
of the button as given below.
{% tabs %}
{% highlight C# %}
private void buttonAdv1_Click(object sender, EventArgs e) { this.spellCheckerAdv1.SpellCheck(new SpellCheckerAdvEditorWrapper(this.richTextBox1)); }
{% endhighlight %}
{% highlight VB %}
Private Sub buttonAdv1_Click(sender As Object, e As EventArgs) Me.spellCheckerAdv1.SpellCheck(New SpellCheckerAdvEditorWrapper(Me.richTextBox1)) End Sub
{% endhighlight %}
{% endtabs %}
SpellCheckerAdv provide built-in dictionary whose Path can be set using DictionaryPath property in SpellCheckerAdv.
{% tabs %}
{% highlight C# %}
this.spellCheckerAdv1.DictionaryPath = "Syncfusion_en_us.dic";
{% endhighlight %}
{% highlight VB %}
Me.spellCheckerAdv1.DictionaryPath = "Syncfusion_en_us.dic"
{% endhighlight %}
{% endtabs %}
You can spell check any language(culture) by adding the respective culture to the SpellCheckerAdv.Culture property and add the dictionaries which contains the basic word file and grammar file to the SpellCheckerAdv.Dictionaries collection.
The following dictionary types are used for spell-checking,
- Hunspell
- Ispell
- OpenOffice
N> Refer the [Load your own dictionaries for any language] (https://help.syncfusion.com/windowsforms/spell-checker/custom-dictionary#load-your-own-dictionaries-for-any-language) page to know more about how to add and use the Dictionary for any culture to an application.
If you want to add words that is not available in existing dictionary, you can add it using CustomDictionary
. This dictionary does not has a grammar file, it accepts only dictionary file that contains a list of words. Users can also add words to this custom dictionary by clicking Add to Dictionary
button available in dialog or context menu.
N> Refer the Adding Custom Dictionary page to know more about how to add and use the custom dictionary to an application.
Look and feel of the SpellCheckerAdv can be customize using VisualStyle property.
{% tabs %}
{% highlight C# %}
this.spellCheckerAdv1.VisualStyle = SpellCheckerAdvStyle.Office2016Colorful;
{% endhighlight %}
{% highlight VB %}
Me.spellCheckerAdv1.VisualStyle = SpellCheckerAdvStyle.Office2016Colorful
{% endhighlight %}
{% endtabs %}