Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Windows;
Using System. Windows. Controls;
Using System. Windows. Markup;
Using System. Windows. Media;
Using System. Reflection;
Using System. Windows. Input;
Using System. Windows. Documents;
Namespace WpfApplication1
{
Class Test: Window
{
String str = null;
[STAThread]
Static void Main ()
{
Application app = new Application ();
App. Run (new Test ());
}
/// <Summary>
/// Exaggerated. The key is that events can be added to each word .. Run or inherited from UElement;
/// </Summary>
Public Test ()
{
Content = str;
Title = "Format the Text ";
TextBlock txt = new TextBlock ();
Txt. FontFamily = new System. Windows. Media. FontFamily (" ");
Txt. FontSize = 48;
Txt. HorizontalAlignment = HorizontalAlignment. Center;
Txt. VerticalAlignment = verticalignment. Center;
Content = txt;
String strquote = "To be, or not to be, that is the question" + Environment. NewLine + "Click Me !! ";
String [] strwords = strquote. Split ();
Foreach (var item in strwords)
{
Run run = new Run (item );
Run. MouseDown + = new MouseButtonEventHandler (run_MouseDown );
Txt. Inlines. Add (run );
Txt. Inlines. Add ("");
}
Content = txt;
}
/// <Summary>
/// Click an event
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Void run_MouseDown (object sender, MouseButtonEventArgs e)
{
Run run = sender as Run;
If (e. ChangedButton = MouseButton. Left)
{
Run. FontStyle = run. FontStyle = FontStyles. Italic? FontStyles. Normal: FontStyles. Italic;
}
If (e. ChangedButton = MouseButton. Right)
{
Run. FontWeight = run. FontWeight = FontWeights. Bold? FontWeights. Normal: FontWeights. Bold;
}
}
/// <Summary>
/// Character Input
/// </Summary>
/// <Param name = "e"> </param>
Protected override void OnTextInput (TextCompositionEventArgs e)
{
Base. OnTextInput (e );
Str = (string) Content;
If (e. Text = "\ B ")
{
If (str. Length> 0)
{
Str = str. Substring (0, str. Length-1 );
}
}
Else
{
Str + = e. Text;
}
// Content = str;
}
}
}