Handlers for Form Changes
- From: "Liz" <liz@xxxxxxxxxxxxxxx>
- Date: Fri, 12 Oct 2007 22:12:19 -0500
I have a form with about 25-30 TextBoxes, ComboBoxes, etc; if the user does
not make any changes to the form I don't want to post a "Cancel Changes?"
dialog when they exit the form ... so this is what I'm doing to detect
changes:
// this gets called from the Form_Load event handler
private void SetFormStateChangeHandlers(Control parent) // on 1st
entry, "this" is passed to the method
{
foreach (Control control in parent.Controls)
{
if (control is TextBox || control is ComboBox)
{
control.TextChanged += new
EventHandler(controlStateChanged);
}
// handle container controls which might have child controls
if (control.Controls.Count > 0)
{
SetFormStateChangeHandlers(control);
}
}
}
// set the class-level var to be tested on form exit
void controlStateChanged(object sender, EventArgs e)
{
FormHasChanged = true;
}
This *does* work, but there is at least one shortcoming, which is that if
the user changes a control and then undoes the change, I'm not detecting
that ... also, I'm just wondering if there's a better, more straightforward
way of handling the issue ... any other ideas out there?
TIA
Liz
.
- Follow-Ups:
- Re: Handlers for Form Changes
- From: Peter Duniho
- Re: Handlers for Form Changes
- Prev by Date: Re: Using API to shutdown a PC
- Next by Date: Re: Handlers for Form Changes
- Previous by thread: Re: Using API to shutdown a PC
- Next by thread: Re: Handlers for Form Changes
- Index(es):
Relevant Pages
|