I am doing a TextBox as if it could store a null value. To do this, I have a NullMode variable that indicates that the value is stored in Null, and in TextChanged I am set to false, and for a specific user action I set true and Text to a value indicating that null exists inside the text field. Then, based on NullMode, the text box is drawn differently.
Now I have a semaphop-like approach to prevent the event descriptor from triggering when I don't need it. Here's what it looks like:
private void input_TextChanged(object sender, EventArgs e)
{
if (_preventTextBoxEvents)
return;
_preventTextBoxEvents = true;
NullMode = false;
ValidateInput();
_preventTextBoxEvents = false;
}
, -, nullmode, _preventTextBoxEvents, true, .
! , - ! Text "". , , . (e.Cancel = true FormClosing !) , . ( try-catch).
, Text = "". OnTextChanged , TextChanged, , _preventTextBoxEvents , / .
?