public TextBoxKeyPress()
{
InitializeComponent();
txtInput.KeyUp += new KeyEventHandler(txtInput_KeyUp);
txtInput.KeyDown += new KeyEventHandler(txtInput_KeyDown);
}
void txtInput_KeyDown(object sender, KeyEventArgs e)
{
s = "";
switch (e.Key)
{
case Key.Left:
{
s = ".";
e.Handled = true;
break;
}
case Key.Right:
{
s = "-";
e.Handled = true;
break;
}
}
}
void txtInput_KeyUp(object sender, KeyEventArgs e)
{
TextBox txb = (TextBox)sender;
if (Keyboard.Modifiers == ModifierKeys.Shift) return;
if (Keyboard.Modifiers == ModifierKeys.Control) return;
if (txb.SelectedText.Length > 0)
txb.SelectedText = "";
switch (e.Key)
{
case Key.Left:
{
s = ".";
e.Handled = true;
break;
}
case Key.Right:
{
s = "-";
e.Handled = true;
break;
}
}
int i = txb.SelectionStart;
txb.Text = txb.Text.Insert(i, s);
txb.Select(i + 1, 0);
e.Handled = true;
}
BUT the problem is when I want to write in the textbox .-. actually ..- is written because the arrows do move left/right once and then write . or - , they do the both! how to disable the basic arrows functions ??
any ideas?