Mega Code Archive

 
Categories / C# / WPF
 

Change font

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   x:Class="Typography_Samp.Page1"   WindowTitle="Typography Variants Sample">   <FlowDocument Name="tf1" FontSize="18" ColumnWidth="600.0">     <Paragraph FontSize="20" Margin="0,0,0,10">Typography Variants Sample</Paragraph>     <Paragraph Margin="0,0,0,50">       this is a test     </Paragraph>     <Paragraph>       <StackPanel Orientation="Horizontal" Margin="10" HorizontalAlignment="Center">         <Button Click="changeArial">Arial</Button>         <Button Click="changePalatino">Palatino Linotype</Button>         <Button Click="changeTimes">Times New Roman</Button>         <Button Click="changeVerdana">Verdana</Button>       </StackPanel>       <LineBreak/>       Normal <Run Typography.Variants="Superscript">superscript</Run>       <Run Typography.Variants="Subscript">subscript</Run>       1<Run Typography.Variants="Ordinal">st</Run>       H<Run Typography.Variants="Inferior">2</Run>       SO<Run Typography.Variants="Inferior">4</Run>     </Paragraph>        </FlowDocument> </Page> //File:Window.xaml.cs using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace Typography_Samp {   public partial class Page1 : Page   {         public void changeArial(object sender, RoutedEventArgs e)         {             tf1.FontFamily = new FontFamily("Arial");         }         public void changePalatino(object sender, RoutedEventArgs e)         {             tf1.FontFamily = new FontFamily("Palatino Linotype");         }         public void changeTimes(object sender, RoutedEventArgs e)         {             tf1.FontFamily = new FontFamily("Times New Roman");         }         public void changeVerdana(object sender, RoutedEventArgs e)         {             tf1.FontFamily = new FontFamily("Verdana");         }     } }