Using System;
Using System. Windows;
Using System. Windows. Input;
Namespace xiaohai. TextInput
{
Class Example: Application
{
[STAThread]
Public static void Main ()
{
Example app = new Example ();
App. ShutdownMode = ShutdownMode. OnMainWindowClose;
App. Run ();
}
Protected override void OnStartup (StartupEventArgs e)
{
Base. OnStartup (e );
Window winMain = new Window ();
WinMain. Title = "Main Window ";
For (int I = 0; I <2; I ++)
{
Window win = new Window ();
Win. Width = win. Height = 300;
Win. Title = "Window" + I. ToString ();
Win. KeyDown + = WindowOnKeyDown;
Win. TextInput + = WindowOnTextInput;
Win. Show ();
}
WinMain. Show ();
}
Static void WindowOnTextInput (object sender, TextCompositionEventArgs e)
{
Window w = sender as Window;
If (e. Text = "/B" & w. Content. ToString (). Length> 0)
W. Content = e. Text. Substring (0, w. Content. ToString (). Length-1 );
Else if (e. Text. Length> 0 &&! Char. IsControl (e. Text [0])
W. Content + = e. Text;
}
Static void WindowOnKeyDown (object sender, KeyEventArgs e)
{
Window w = sender as Window;
If (e. Key = Key. Up)
{
W. Top-= 0.05 * w. Height;
}
Else if (e. Key = Key. Down)
W. Top ++ = 0.05 * w. Height;
Else if (e. Key = Key. Left)
W. Left-= 0.1 * w. Width;
Else if (e. Key = Key. Right)
W. Left ++ = 0.1 * w. Width;
Else if (e. Key = Key. Enter)
{
W. Left = SystemParameters. WorkArea. Width/2-w. Width/2;
W. Top = SystemParameters. WorkArea. Height/2-w. Height/2;
}
}
}
}