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

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Windows Presentation Foundation » FontScreenshots 
Font Properties Sample
Font Properties Sample
     

<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

   
    
    
    
    
  
Related examples in the same category
1.FontSize unitsFontSize units
2.Change a Control's Font Weight on Mouse OverChange a Control's Font Weight on Mouse Over
3.Display Simple Text with TextBlock and set font, alignmentDisplay Simple Text with TextBlock and set font, alignment
4.Section Font StyleSection Font Style
5.Adding TextBlock to StackPanel with different font sizeAdding TextBlock to StackPanel with different font size
6.Using text format property aliases
7.Programmatically change the FontFamily property of a TextBlock element.Programmatically change the FontFamily property of a TextBlock element.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.