Font Properties Sample : Font « Windows Presentation Foundation « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net Tutorial » Windows Presentation Foundation » Font 




<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="Honeydew">
    <TextBlock FontWeight="Bold" FontSize="14">FontFamly:</TextBlock>
    <StackPanel Orientation="Horizontal" Margin="0,0,0,10">
      <Button Click="OnClick1" Background="Silver" Margin="3">Arial</Button>
      <Button Click="OnClick2" Background="Silver" Margin="3">Courier New</Button>
      <Button Click="OnClick3" Background="Silver" Margin="3">Tahoma</Button>
      <Button Click="OnClick4" Background="Silver" Margin="3">Times New Roman</Button>
      <Button Click="OnClick5" Background="Silver" Margin="3">Verdana</Button>
    </StackPanel>

    <TextBlock FontWeight="Bold" FontSize="14">Foreground Color:</TextBlock>
    <StackPanel Orientation="Horizontal" Margin="0,0,0,10">
      <Button Click="OnClick11" Foreground="White" Background="Black" Margin="3">Black</Button>
      <Button Click="OnClick12" Background="Blue" Margin="3">Blue</Button>
      <Button Click="OnClick13" Background="Green" Margin="3">Green</Button>
      <Button Click="OnClick14" Background="Red" Margin="3">Red</Button>
      <Button Click="OnClick15" Background="Yellow" Margin="3">Yellow</Button>
    </StackPanel>


    <TextBlock FontWeight="Bold" FontSize="14" VerticalAlignment="Center">FontSize:</TextBlock>
    <StackPanel Orientation="Horizontal" Margin="0,0,0,10">
      <RadioButton Click="OnClick6" Margin="3">point</RadioButton>
      <RadioButton Click="OnClick7" Margin="3">10 point</RadioButton>
      <RadioButton Click="OnClick8" Margin="3">12 point</RadioButton>
      <RadioButton Click="OnClick9" Margin="3">14 point</RadioButton>
      <RadioButton Click="OnClick10" Margin="3">16 point</RadioButton>
    </StackPanel>

    <TextBlock FontSize="12" Name="txt1">The FontFamily is set to Arial.</TextBlock>
    <TextBlock FontSize="12" Name="txt3">The FontSize is set to 12 point.</TextBlock>
    <TextBlock FontSize="12" Name="txt4" Margin="0,0,0,15">The Foreground color is set to Black.</TextBlock>

    <FlowDocumentReader>
      <FlowDocument Name="txt2" FontFamily="Arial" FontSize="12" Foreground="Black">
        <Paragraph>
          this is a test
        </Paragraph>
      </FlowDocument>
    </FlowDocumentReader>
  </StackPanel>
</Window>

//File:Window.xaml.vb

Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Media

Namespace WpfApplication1

  Public Partial Class Window1
    Inherits Window
    Public Sub OnClick1(sender As Object, e As RoutedEventArgs)
      txt1.Text = "The FontFamily is set to Arial."
      txt2.FontFamily = New FontFamily("Arial")
    End Sub

    Public Sub OnClick2(sender As Object, e As RoutedEventArgs)
      txt1.Text = "The FontFamily is set to Courier new."
      txt2.FontFamily = New FontFamily("Courier new")
    End Sub

    Public Sub OnClick3(sender As Object, e As RoutedEventArgs)
      txt1.Text = "The FontFamily is set to Tahoma."
      txt2.FontFamily = New FontFamily("Tahoma")
    End Sub

    Public Sub OnClick4(sender As Object, e As RoutedEventArgs)
      txt1.Text = "The FontFamily is set to Times new Roman."
      txt2.FontFamily = New FontFamily("Times new Roman")
    End Sub

    Public Sub OnClick5(sender As Object, e As RoutedEventArgs)
      txt1.Text = "The FontFamily is set to Verdana."
      txt2.FontFamily = New FontFamily("Verdana")
    End Sub

    Public Sub OnClick6(sender As Object, e As RoutedEventArgs)
      txt3.Text = "The FontSize is set to 8 point."
      txt2.FontSize = 8
    End Sub

    Public Sub OnClick7(sender As Object, e As RoutedEventArgs)
      txt3.Text = "The FontSize is set to 10 point."
      txt2.FontSize = 10
    End Sub

    Public Sub OnClick8(sender As Object, e As RoutedEventArgs)
      txt3.Text = "The FontSize is set to 12 point."
      txt2.FontSize = 12
    End Sub

    Public Sub OnClick9(sender As Object, e As RoutedEventArgs)
      txt3.Text = "The FontSize is set to 14 point."
      txt2.FontSize = 14
    End Sub

    Public Sub OnClick10(sender As Object, e As RoutedEventArgs)
      txt3.Text = "The FontSize is set to 16 point."
      txt2.FontSize = 16
    End Sub

    Public Sub OnClick11(sender As Object, e As RoutedEventArgs)
      txt4.Text = "The Foreground color is set to Black."
      txt2.Foreground = Brushes.Black
    End Sub

    Public Sub OnClick12(sender As Object, e As RoutedEventArgs)
      txt4.Text = "The Foreground color is set to Blue."
      txt2.Foreground = Brushes.Blue
    End Sub

    Public Sub OnClick13(sender As Object, e As RoutedEventArgs)
      txt4.Text = "The Foreground color is set to Green."
      txt2.Foreground = Brushes.Green
    End Sub

    Public Sub OnClick14(sender As Object, e As RoutedEventArgs)
      txt4.Text = "The Foreground color is set to Red."
      txt2.Foreground = Brushes.Red
    End Sub

    Public Sub OnClick15(sender As Object, e As RoutedEventArgs)
      txt4.Text = "The Foreground color is set to Yellow."
      txt2.Foreground = Brushes.Yellow
    End Sub
  End Class
End Namespace
WPF Font Properties Sample














16.74.Font
16.74.1.FontSize unitsFontSize units
16.74.2.Change a Control's Font Weight on Mouse OverChange a Control's Font Weight on Mouse Over
16.74.3.Display Simple Text with TextBlock and set font, alignmentDisplay Simple Text with TextBlock and set font, alignment
16.74.4.Section Font StyleSection Font Style
16.74.5.Adding TextBlock to StackPanel with different font sizeAdding TextBlock to StackPanel with different font size
16.74.6.Using text format property aliasesUsing text format property aliases
16.74.7.Programmatically change the FontFamily property of a TextBlock element.Programmatically change the FontFamily property of a TextBlock element.
16.74.8.Font Properties SampleFont Properties Sample
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.