You can do the following:
protected override void OnKeyPress(KeyPressEventArgs e)
{
e.Handled = !(char.IsDigit(e.KeyChar) || (e.KeyChar == Keys.Decimal && !textBox.Text.Contains(".")) && !char.IsControl(e.KeyChar);
base.OnKeyPress(e);
}
You will need to worry about multiple decimal points. You might want to check if the textbox already has a decimal point. I do not work with WinForms anymore, but the value in the textbox should be what the value is before the entry. I am also suspicious that there is no sender in the OnKeyPress method.