Mega Code Archive

 
Categories / C# Tutorial / WPF
 

Override OnTextInput method to get the input from key board

using System; using System.Windows; using System.Windows.Input; using System.Windows.Media;     public class MainClass : Window     {         [STAThread]         public static void Main()         {             Application app = new Application();             app.Run(new MainClass());         }         public MainClass()         {             Content = "";         }         protected override void OnTextInput(TextCompositionEventArgs args)         {             base.OnTextInput(args);             string str = Content as string;             if (args.Text == "\b")             {                 if (str.Length > 0)                     str = str.Substring(0, str.Length - 1);             }             else             {                 str += args.Text;             }             Content = str;         }     }