MolC MolC - 1 month ago 6x
C# Question

How to make textBox default value not avalible to remove

how to make textBox default value, for example 0, in my textBox not available to remove, in other words, do not allow user make textBox empty , but allow to change it, if user removed his value, I want keep my textbox with zero?


One approach would be subscribing to TextChanged event and assigning default value when it is empty.

textBox.TextChanged += textBox_TextChanged; 

private void currencyTextBox_TextChanged(object sender, EventArgs e)
       textBox.Text = "0";