By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,899 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,899 IT Pros & Developers. It's quick & easy.

Some Controls Do Not Work After OnClosing is Cancelled

P: n/a
Windows Experts:

1. I have a desktop application with a UserControl that contains
controls: TextBoxes, RadioButtons, CheckBoxes and NumericUpDowns.

2. I want to warn the user that, if there is unsaved data within my
UserControl when he tries to 'X' out of the entire application, to
display a MessageBox.

3. Unfortunately, System.Windows.Forms.UserControl does not have a
Closing event, so I use the Closing event of the Form that is calling
my UserControl.

4. During the MainForm.OnClosing() processing, if I set e.Cancel =
true; (to return back to my UserControl), some controls work and some
do not.

5. The controls that do not work are RadioButtons, CheckBoxes and the
up/down arrow of the NumericUpDown (I can still type in data into the
TextBox-like part of the NumericUpDown).

6. Those that do are TextBoxes and ComboBoxes.
--------------------------

I suspect it has something to do with attempting to leave the
UserControl and returning back.

I tried by calling all conceivable methods of my UserControl, such as
Refresh(), Update(), Focus(), Show(), but none seemed to work.

What is the logic or state of affairs when the user tries to leave a
control, but the main form's OnClosing() event handler cancels the
closing?

Or, is there a better way to intercept the Closing of the UserControl
and to stay entirely within the UserControl?

Thanks
Jul 9 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Oops.

During my research, I had turned on the UserControl OnValidating()
event and had set e.Cancel = true, but saw no visible results at that
time.

Just now, I discovered that I had left e.Cancel = true, within
UserControl.OnValidating()

Problem is solved, but a curiosity: Why did some controls work and
others did not when I set:

UserControl.OnValidating()
{
e.Cancel = true;
}
Jul 9 '08 #2

P: n/a
On Jul 9, 3:53*pm, richard.mart...@raymondjames.com wrote:
Oops.

During my research, I had turned on the UserControl OnValidating()
event and had set e.Cancel = true, but saw no visible results at that
time.

Just now, I discovered that I had left e.Cancel = true, within
UserControl.OnValidating()

Problem is solved, but a curiosity: Why did some controls work and
others did not when I set:

UserControl.OnValidating()
{
* * e.Cancel = true;

}- Hide quoted text -

- Show quoted text -
Hi,

Maybe those controls were disposed before you cancel the closing.
Jul 9 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.