Hey there,
So at the moment I don't really understand why you decided to have both KeyUp and KeyDown as i think KeyUp should not even come up as you've "handled" with it in KeyDown. Though i think you are aiming in a right direction I've smashed some code together for you (That did work for me)
I also couldn't really figure out why you are casting sender to a TextBox (the only reason i could come up with is that you'd like to use the mechanism on multiple textboxes). With that being said, if you ever want to cast sender to a specific object it's best to first check if it's actually that object otherwise you're code will crash.
Here's my KeyDown function for you:
private void txtInput_KeyDown(object sender, KeyEventArgs e)
{
if (sender is TextBox)
{
TextBox textBox = (TextBox)sender;
if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)
{
e.Handled = true;
char insert;
if (e.KeyCode == Keys.Left)
{
insert = '.';
}
else
{
insert = '-';
}
int i = textBox.SelectionStart;
textBox.Text = textBox.Text.Insert(i, insert.ToString());
textBox.Select(i + 1, 0);
}
}
}