RichTextBox control WPF in VB.NET

Here we will see that how to use RichTextBox control.
  • 3182
 

Here we will see that how to use RichTextBox control.

RichTextBox control

The RichTextBox control that supports rich formatting, automatic line wrapping, HTML and RTF import/export, table support, images and more.

For example

Drag and drop three TextBlock,three Button control on the form.

The window form looks like this.

r1.gif

Figure1.gif

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>

        <Canvas x:Name="LayoutRoot" Background="White">

            <StackPanel Orientation="Horizontal" Canvas.Left="0" Canvas.Top="20" Height="30" Width="184">

            <Button x:Name="makeBold" Width="47" Height="23"  Margin="10, 2, 2, 2" ToolTipService.ToolTip="Bold">

            <TextBlock x:Name="boldText" Text="B" FontFamily="Arial" FontSize="14" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" />

                </Button>

                <Button x:Name="makeItalic" Width="55" Height="23" Margin="2" ToolTipService.ToolTip="Italic">

                <TextBlock x:Name="italicText" Text="I" FontFamily="Arial" FontSize="14" FontStyle="Italic" HorizontalAlignment="Center" VerticalAlignment="Center" />

                </Button>

                <Button x:Name="makeUnderline" Width="56" Height="20" Margin="2" ToolTipService.ToolTip="Underline">

                <TextBlock x:Name="underlineText" Text="U" FontFamily="Arial" FontSize="14" TextDecorations="Underline" HorizontalAlignment="Center" VerticalAlignment="Center" />

            </Button>  

            </StackPanel>

            <RichTextBox Height="136" Name="RichTextBox2" Width="289" Canvas.Left="20" Canvas.Top="69" >

            </RichTextBox>

        </Canvas>

</Grid>

</Window>

 

Now run the application and enter the text into RichTextBox control.

r2.gif

Figure2.gif

Now select the text and apply Bold on the text.

r3.gif

Figure3.gif

Similarly, we can test for Italic and underline text.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.