Exemple #1
0
 public void TextBox1_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         TextBox1.MoveFocus(TraversalRequest);
     }
     else if (e.Key == Key.Subtract)
     {
         var box   = (System.Windows.Controls.TextBox)sender;
         var caret = box.CaretIndex;
         box.Text       = box.Text.Insert(box.CaretIndex, "-");
         box.CaretIndex = caret + 1;
         e.Handled      = true;
     }
 }
Exemple #2
0
 public void TextBox1_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         TextBox1.MoveFocus(traversalRequest);
     }
     if (e.Key == Key.Subtract)
     {
         System.Windows.Controls.TextBox box = (System.Windows.Controls.TextBox)sender;
         String text  = box.Text;
         int    caret = box.CaretIndex;
         if (box.SelectionLength > 0)
         {
             text = text.Substring(0, box.SelectionStart) + text.Substring(box.SelectionStart + box.SelectionLength);
         }
         box.Text       = text.Insert(box.CaretIndex, "-");
         box.CaretIndex = caret + 1;
         e.Handled      = true;
     }
 }