Some Controls Do Not Work After OnClosing is Cancelled

  • Thread starter richard.martino
  • Start date
R

richard.martino

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
 
R

richard.martino

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;
}
 
I

Ignacio Machin ( .NET/ C# MVP )

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top