Purging window messages under a given condition!

M

mehdi_mousavi

Hi folks,
Consider a dialog box, that contains a menu, toolbar and a tab control
that contains some pages, and the first tab page contains some textbox
controls as well as a datetimepicker and some buttons. Among the
textboxes I've mentioned, there's a textbox that is supposed to get the
address of a customer (including street, city, state, zipcode and the
like) all in a given multi-line textbox. So I've to parse the entered
string *and show the parsing result to the user* (in a new dialog box)
before leaving to another TabStop-enabled control, including other
pages of the tab control, the datetime picker ctrl and the like.

So, I've to purge any pending message already in the message queue, if
the parsed address is not confirmed by the user and keep the focus on
the address textbox. i.e., consider that an address is entered in the
multi-line textbox, and then user clicks on a second tab page of the
tab control with his mouse, or clicks on the dropdown arrow of the
datetime picker control. A dialog box is shown to the user to confirm
that the address is parsed correctly, and if he clicks on the ok
button, I've to process those pending messages.

However, the problem is that if user clicks on the "Cancel" button of
the confirmation dialog, I've to purge any messages (including those
clicks on second tab page, and the datetime picker control) and set the
focus to the address textbox, so neither the tab index is changed, nor
the datetime picker window opens up!

I tried many patterns to achieve this but there is always a problem, so
I decided to ask your help. The effect I'm trying to achieve is exactly
implemented in "Microsoft Small Business Accounting 2006", ie., I'm
trying to mimic that.

Any help would be highly appreciated,

TIA,
Mehdi
 
N

Nicholas Paldino [.NET/C# MVP]

Mehdi,

Did you look at the Validating event on the TextBox? You can put up
your dialog box in that, and if it is not correct, you can cancel the event,
eliminating the movement to the next control.

Also, you won't have to worry about moving to the next control or
anything like that, windows will take care of it for you.

Hope this helps.
 
M

mehdi_mousavi

Well the problem with this solution is that the validating event on the
address textbox is raised twice when I try to activate another tab page
of the tab control. From then on, the event is get called twice, no
matter what control on the page I'm trying to activate.

Would you please let me know what is wrong with this?

Any help would be highly appreciated,

Cheers,
Mehdi
Mehdi,

Did you look at the Validating event on the TextBox? You can put up
your dialog box in that, and if it is not correct, you can cancel the event,
eliminating the movement to the next control.

Also, you won't have to worry about moving to the next control or
anything like that, windows will take care of it for you.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)



mehdi_mousavi said:
Hi folks,
Consider a dialog box, that contains a menu, toolbar and a tab control
that contains some pages, and the first tab page contains some textbox
controls as well as a datetimepicker and some buttons. Among the
textboxes I've mentioned, there's a textbox that is supposed to get the
address of a customer (including street, city, state, zipcode and the
like) all in a given multi-line textbox. So I've to parse the entered
string *and show the parsing result to the user* (in a new dialog box)
before leaving to another TabStop-enabled control, including other
pages of the tab control, the datetime picker ctrl and the like.

So, I've to purge any pending message already in the message queue, if
the parsed address is not confirmed by the user and keep the focus on
the address textbox. i.e., consider that an address is entered in the
multi-line textbox, and then user clicks on a second tab page of the
tab control with his mouse, or clicks on the dropdown arrow of the
datetime picker control. A dialog box is shown to the user to confirm
that the address is parsed correctly, and if he clicks on the ok
button, I've to process those pending messages.

However, the problem is that if user clicks on the "Cancel" button of
the confirmation dialog, I've to purge any messages (including those
clicks on second tab page, and the datetime picker control) and set the
focus to the address textbox, so neither the tab index is changed, nor
the datetime picker window opens up!

I tried many patterns to achieve this but there is always a problem, so
I decided to ask your help. The effect I'm trying to achieve is exactly
implemented in "Microsoft Small Business Accounting 2006", ie., I'm
trying to mimic that.

Any help would be highly appreciated,

TIA,
Mehdi
 
B

Bruce Wood

mehdi_mousavi said:
Well the problem with this solution is that the validating event on the
address textbox is raised twice when I try to activate another tab page
of the tab control. From then on, the event is get called twice, no
matter what control on the page I'm trying to activate.

Would you please let me know what is wrong with this?

Perhaps you should post some code (including the code generated by the
Windows Forms Designer). This has never happened to me (and I use
Validating events a lot).
 

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

Similar Threads


Top