WPF Apply Font Properties on text in VB.NET

In this article you will learn how to apply different types of font properties to the text in WPF.
  • 2333

This article shows a sample application which produces a dialog box that allows the user to customize values of font properties, for example, FontStyle, FontSize, and FontColor. It also demonstrates techniques for creating a modal dialog box using Windows Presentation Foundation (WPF).

<Window 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
    x:Class="WpfApplication1.Window1"
    Title="Font Properties VB Sample">
     <StackPanel Background="LemonChiffon">
        <TextBlock FontWeight="Bold" FontSize="14">FontFamly:</TextBlock>
        <StackPanel Orientation="Horizontal" Margin="0,0,0,10">
           <Button Click="OnClick1" Background="Pink" Margin="3" FontSize="13">Arail Black</Button>
            <Button Click="OnClick2" Background="Pink" Margin="3" FontSize="13">Comic Sans MS</Button>
            <Button Click="OnClick3" Background="Pink" Margin="3"FontSize="13">Forte</Button>
            <Button Click="OnClick4" Background="Pink" Margin="3" FontSize="13">Lucida Calligraphy</Button>
            <Button Click="OnClick5" Background="Pink" Margin="3">Ravie</Button>
        </StackPanel>
 
        <TextBlock FontWeight="Bold" FontSize="14">Foreground Color:</TextBlock>
 
       <StackPanel Orientation="Horizontal" Margin="0,0,0,10">
 
           <Button Click="OnClick11" Foreground="White" Background="Red" Margin="3"FontSize="13">Red</Button>
            <Button Click="OnClick12" Foreground="White" Background="Blue" Margin="3"FontSize="13">Blue</Button>
            <Button Click="OnClick13" Foreground="White" Background="Green" Margin="3"FontSize="13">Green</Button>
            <Button Click="OnClick14" Foreground="White" Background="Purple" Margin="3"FontSize="13">Purple</Button>
            <Button Click="OnClick15" Foreground="White" Background="Orange" Margin="3"FontSize="13">Orange</Button>
        </StackPanel>
 
        <TextBlock FontWeight="Bold" FontSize="14"VerticalAlignment="Center">FontSize:</TextBlock>
        <StackPanel Orientation="Horizontal" Margin="0,0,0,10">
            <RadioButton Click="OnClick6" Margin="3" FontSize="13">8 point</RadioButton>
            <RadioButton Click="OnClick7" Margin="3" FontSize="13">12 point</RadioButton>
            <RadioButton Click="OnClick8" Margin="3" FontSize="13">16 point</RadioButton>
            <RadioButton Click="OnClick9" Margin="3" FontSize="13">20 point</RadioButton>
            <RadioButton Click="OnClick10" Margin="3" FontSize="13">24 point</RadioButton>
        </StackPanel>
 
        <TextBlock FontSize="12" Name="txt1" Margin="0,0,0,2">The FontFamily is set to Arial.</TextBlock>
 
       <TextBlock FontSize="12" Name="txt4" Margin="0,0,0,2">The Foreground color is set to Black.</TextBlock>
        <TextBlock FontSize="12" Name="txt3">The FontSize is set to 12 point.</TextBlock>
        <FlowDocumentReader>
            <FlowDocument Name="txt2" FontFamily="Arial" FontSize="14" Foreground="Black">
                <Paragraph>
                    Welcome to Vbdotnetheaven
                
</Paragraph>
            </FlowDocument>
        </FlowDocumentReader>
    </StackPanel>
</
Window>

Output 

fontproperty1.gif

Here you see the font style is set as Arial Black, font color Red and font size is 20 points. Now, lets do some changes in the output window and have fun.

fontproperty2.gif

I hope you will enjoy this.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.