MolC MolC - 1 year ago 124
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?

Answer Source

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";   
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download