I have a groupbox with a background of a certain color containing a textbox. I was thinking of ways to help the user see that the textbox was dirty, and thought perhaps changing the background groupbox color and/or adding a “*” to the name of the groupbox and/or Form Text would be nice. But I can’t get the event to even change the property of _isDirty. Let alone implement this idea. I’m sure that someone has done something similar and Hope that you could help me. I’m working with C# .Net framework 2.0 (it should also work in 4.0 but that’s backwards compatible I believe). IDE is Visual Studios 10.
The idea is when the textbox is changed, the _isDirty “flag”/”property” will be changed, as well as when it has been saved:
_isDirty = true when textbox has been changed
_isDirty = false when textbox has been saved
This is what I have at the moment.. though I’ve tried different things including the INotify which wasn’t working for me at all…
public static bool _isDirty = false;
private void textBox1_TextChanged(object sender, EventArgs e)
{
string newtext = textBox1.Text;
if (currentText != newtext)
{
// This solves the problem of initial text being tagged as changed text
if (currentText == "")
{
_isDirty = false;
}
else
{
//OnIsDirtyChanged();
_isDirty = true; //might have to change with the dirty marker
}
currentText = newtext;
}
}
public bool IsDirty
{
get { return _isDirty; }
set
{
if (_isDirty != value)
{
_isDirty = value;
OnIsDirtyChanged(_isDirty);
}
}
}
protected void OnIsDirtyChanged(bool _isDirty)
{
if (_isDirty == true)
{
this.Text += "*";
}
}
If someone has a different suggestion to how I go about this, or a nicer user friendly way of doing this, I’m open for suggestions.. Thanks!
EDIT: The answer is actually in 2 parts! The correction to make the property change event WORK was given by BRAM.
If you want to know how to change background color, then look at ZARATHOS’S answer.
Unfortunately I can only mark ONE answer, so going to mark the one that got the main bit working.
You are setting _isDirty so the event does not fire.
You need to set IsDirty.
And this line is wrong
Needs to be
Assuming that is the notification event.