WPF Spell checker in VB.NET

In this article we will learn how to use Spell checker in WPF using VB.NET.
  • 2988
Download Files:
 

In this article we will learn how to use Spell checker in WPF using VB.NET.

Spell checker

The spell checker is used to check spelling of our content in WPF application.

Example

Taking a TextBlock control and RichTextBox control on the form.

The form looks like this.

sp.gif
 

Figure 1.

XAML code

<Window x:Class="MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="MainWindow" Height="350" Width="525">

    <Grid>

        <TextBlock Height="23" HorizontalAlignment="Left" Margin="0,23,0,0" Name="TextBlock1" Text="Enter content:" VerticalAlignment="Top" Width="141" FontSize="18" Foreground="LawnGreen" />

        <RichTextBox Height="100" HorizontalAlignment="Left" Margin="0,44,0,0" Name="RichTextBox1" VerticalAlignment="Top" Width="200" Background="DodgerBlue" FontSize="18" />

    </Grid>

</Window>

 

Now double click on the RichTextBox and add the following code.

 

Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs) Handles RichTextBox1.TextChanged

        SpellCheck.SetIsEnabled(RichTextBox1, True)

        SpellCheck.SetSpellingReform(RichTextBox1, SpellingReform.PreAndPostreform)

    End Sub

 

Now run the application and test it.

sp1.gif
 

Figure 2.

This can be done through the property of RichTextBox.

Set the property SpellCheck.IsEnabled="True" property in the RichTextBox after that automatically derive the Spell Checking functionality.

sp2.gif
 

Figure 3.

XAML code

<Window x:Class="MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="MainWindow" Height="350" Width="525">

    <Grid>

        <TextBlock Height="23" HorizontalAlignment="Left" Margin="0,23,0,0" Name="TextBlock1" Text="Enter content:" VerticalAlignment="Top" Width="141" FontSize="18" Foreground="LawnGreen" />

        <RichTextBox Height="100" HorizontalAlignment="Left" Margin="0,44,0,0" Name="RichTextBox1" SpellCheck.IsEnabled="True" AcceptsReturn="True" VerticalAlignment="Top" Width="200" Background="Gold" FontSize="18" />

    </Grid>

</Window>

Now run the application and test it.

sp3.gif
 

Figure 4.

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.