I've run in to an odd problem that I'm hoping you wonderful people can help me with.
I have a windows forms application in .NET 4.5. Contained in the main form, I have a split container. The left pane contains a TreeView, while the right pane contains a TabContainer with several tabs.
On the first of these tabs is a docked panel that is a simple form containing two text boxes and two buttons (Save and Cancel). I have TextChanged event handlers on both text boxes that enable the buttons, and a handler on Validating for the panel.
The idea is that when one of the TextChanged events fires, the panel is marked "dirty", and any attempt to change focus outside the panel displays an error message asking you to either save or cancel the changes and the Validating handler sets e.Cancel to true.
In most cases, this works fine. Here are some cases:
- Change some text and click Cancel - everything behaves correctly
- Change some text and click Save - everything behaves correctly
- Change some text and click somewhere inside the TreeView - everything behaves correctly. A message box is displayed and clicking either Save or Cancel will allow you to move on.
- Change some text and click on any other tab - this is where it gets screwy. A message box is displayed. After dismissing the message box, neither the Save or Cancel buttons will fire their Click events anymore. Because of this, trying to change focus to any other control (or even close the application) results in the message box being displayed again. You're essentially stuck.
I put breakpoints in the TabControl.Selected handler to make sure it wasn't firing before the Validating handler canceled the action, and it doesn't. Breakpoints in the Click handlers for the button are never hit. I'm running out of ideas.
Has anyone seen anything like this before?
Maybe your messagebox does/did just that: change focus.
Do not attempt to set focus from within the Enter, GotFocus, Leave, LostFocus, Validating, or Validated event handlers. Doing so can cause your application or the operating system to stop responding. For more information, see the WM_KILLFOCUS topic in the "Keyboard Input Reference" section, and the "Message Deadlocks" section of the "About Messages and Message Queues" topic in the MSDN library at http://msdn.microsoft.com/library.
I've run in to an odd problem that I'm hoping you wonderful people can help me with.
I have a windows forms application in .NET 4.5. Contained in the main form, I have a split container. The left pane contains a TreeView, while the right pane contains a TabContainer with several tabs.
On the first of these tabs is a docked panel that is a simple form containing two text boxes and two buttons (Save and Cancel). I have TextChanged event handlers on both text boxes that enable the buttons, and a handler on Validating for the panel.
The idea is that when one of the TextChanged events fires, the panel is marked "dirty", and any attempt to change focus outside the panel displays an error message asking you to either save or cancel the changes and the Validating handler sets e.Cancel to true.
In most cases, this works fine. Here are some cases:
- Change some text and click Cancel - everything behaves correctly
- Change some text and click Save - everything behaves correctly
- Change some text and click somewhere inside the TreeView - everything behaves correctly. A message box is displayed and clicking either Save or Cancel will allow you to move on.
- Change some text and click on any other tab - this is where it gets screwy. A message box is displayed. After dismissing the message box, neither the Save or Cancel buttons will fire their Click events anymore. Because of this, trying to change focus to any other control (or even close the application) results in the message box being displayed again. You're essentially stuck.
I put breakpoints in the TabControl.Selected handler to make sure it wasn't firing before the Validating handler canceled the action, and it doesn't. Breakpoints in the Click handlers for the button are never hit. I'm running out of ideas.
Has anyone seen anything like this before?
Maybe your messagebox does/did just that: change focus.
Do not attempt to set focus from within the Enter, GotFocus, Leave, LostFocus, Validating, or Validated event handlers. Doing so can cause your application or the operating system to stop responding. For more information, see the WM_KILLFOCUS topic in the "Keyboard Input Reference" section, and the "Message Deadlocks" section of the "About Messages and Message Queues" topic in the MSDN library at http://msdn.microsoft.com/library.
0 commentaires:
Enregistrer un commentaire