I do not know if it will solve everything you want, but the solution is usually to use MaskedTextBox
". If that does not resolve, either you will have to create your own control (or get a better one than the default), or you will have to do a lot of customization on it (not always the expected result).
If you insist on customizing% s of standard%, to control everything that is required is quite complicated to post a response here.
Unless you only want to format it at the end of the typing, it's simple there, but the user experience will be greatly impaired.
Another alternative to this specific case might be a TextBox
". It's up to you to decide.
To do something simple and only prevent the use of other characters, this might resolve:
private void textBox11_KeyPress(object sender, KeyPressEventArgs e) {
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != ',')) {
e.Handled = true;
MessageBox.Show("este campo aceita somente numero e virgula");
}
if ((e.KeyChar == ',') && ((sender as TextBox).Text.IndexOf('.') > -1)) {
e.Handled = true;
MessageBox.Show("este campo aceita somente uma virgula");
}
}