Text Box OnLeave event not fireing

R

Roy Chastain

I have a TextBox on a TabPage. On the main form that contains the TabControl I have a ToolBar and a menu.

If I type into the TextBox and click a button on that same TabPage the OnLeave fires as expected.

If I type into the TextBox and then click on the ToolBar or go to a Menu, the OnLeave event does not get generated.

Is this expected behavior?

I was using the OnLeave to know that it was time to update something else with the contents of the text box. In this case the
contents of the TextBox need to be put into text that will be saved to a file by the button on the ToolBar or by the FileSave
menu. Since the OnLeave is not getting fired, I am not updating the text before saving the file.

What is the 'normal' pattern for handling the completion of a TextBox when there a dozen or so ways to invoke things that don't
cause it OnLeave to be fired. The current program design makes it somewhat impractical to run around and get the contents of
every TextBox etc when a Save is requested.

Thanks
 
M

Marc Butenko

Yes, this is expected behavior. This is because when you go to the menu the
cursor stays in the TextBox. Run your app and see for yourself that when
you go to the ToolBar or menu that the cursor stays right in the same text
box as when you left the form.

Here is an article on how the events are sequenced that might be of use:
http://msdn.microsoft.com/library/d...fsystemwindowsformscontrolclassleavetopic.asp

--
Marc Butenko
(e-mail address removed)



Roy Chastain said:
I have a TextBox on a TabPage. On the main form that contains the
TabControl I have a ToolBar and a menu.
If I type into the TextBox and click a button on that same TabPage the OnLeave fires as expected.

If I type into the TextBox and then click on the ToolBar or go to a Menu,
the OnLeave event does not get generated.
Is this expected behavior?

I was using the OnLeave to know that it was time to update something else
with the contents of the text box. In this case the
contents of the TextBox need to be put into text that will be saved to a
file by the button on the ToolBar or by the FileSave
menu. Since the OnLeave is not getting fired, I am not updating the text before saving the file.

What is the 'normal' pattern for handling the completion of a TextBox when
there a dozen or so ways to invoke things that don't
cause it OnLeave to be fired. The current program design makes it
somewhat impractical to run around and get the contents of
 
C

Claes Bergefall

Move your code to OnValidate and then in your menu handler
call Validate on the Form

See Marc Butenkos post about the behavoiur

/claes


Roy Chastain said:
I have a TextBox on a TabPage. On the main form that contains the
TabControl I have a ToolBar and a menu.
If I type into the TextBox and click a button on that same TabPage the OnLeave fires as expected.

If I type into the TextBox and then click on the ToolBar or go to a Menu,
the OnLeave event does not get generated.
Is this expected behavior?

I was using the OnLeave to know that it was time to update something else
with the contents of the text box. In this case the
contents of the TextBox need to be put into text that will be saved to a
file by the button on the ToolBar or by the FileSave
menu. Since the OnLeave is not getting fired, I am not updating the text before saving the file.

What is the 'normal' pattern for handling the completion of a TextBox when
there a dozen or so ways to invoke things that don't
cause it OnLeave to be fired. The current program design makes it
somewhat impractical to run around and get the contents of
 

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