Mega Code Archive

 
Categories / Silverlight / UI Controls
 

Implements a TextBlock to Display Key Data Captured from a TextBox Control

<UserControl x:Class='SilverlightApplication3.MainPage'     xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'      xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'     xmlns:d='http://schemas.microsoft.com/expression/blend/2008'      xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006'      mc:Ignorable='d'      d:DesignWidth='640'      d:DesignHeight='480'>      <Grid x:Name="LayoutRoot" Background="Black">              <TextBlock x:Name="txt"                         Foreground="Blue"                         VerticalAlignment="Center"                         HorizontalAlignment="Center"/>              <TextBox x:Name="txtBox"                       Height="30"                       Width="30"                       VerticalAlignment="Bottom"                       HorizontalAlignment="Center">              </TextBox>      </Grid>   </UserControl> //File: Page.xaml.cs  using System;  using System.Windows;  using System.Windows.Controls;  using System.Windows.Input;   namespace SilverlightApplication3   {      public partial class MainPage : UserControl      {          int txtSize = 10;          public MainPage()          {              InitializeComponent();              txtBox.KeyDown += new KeyEventHandler(myCanvas_KeyDown);              txtBox.KeyUp += new KeyEventHandler(txtBox_KeyUp);          }          void myCanvas_KeyDown(object sender, KeyEventArgs e){              txt.FontSize = txtSize;              txt.Text = e.Key.ToString();              txtBox.Text = "";              txtSize += 5;          }          void txtBox_KeyUp(object sender, KeyEventArgs e){              txt.Text = "";              txtSize = 10;          }      }  }