Hi Herfried, Meredith,
|| Why not use a NumericUpDown control.
Lol, It won't take long to get to 3675 and not much longer to reach
438173.
|| or validate the textbox's contents in its 'Validating' event?
Because Meredith wants dynamic reaction. The [+], [-], [*], [/] buttons
enabled as and when and only when the inputs are valid, ie per character.
|| Restricting the user to some keys is always a bad idea.
Is it? Always? Lol.
I think you should prevent the user doing what they shouldn't then you
don't have to tell them off when they get it wrong. ["No, you can't type a
letter into the calculation", or even better "Data Error", or better still
"Error 54"]
|| When using 'KeyDown' to suppress some keys, the user will
|| still be able to paste text into the texbox.
Now you're making sense. I faced exactly the same problem when I did this
exercise.
=================================
Meredith,
One option on validation is that you let the user do what they want but if
a box has a bad value, set its background to some suitable colour, eg light
red. and put the nature of the error in the status bar. This informs the user
of the error without interrupting them with dialogue boxes. It also allows
them to intentionally use cut-and-paste to bring in mixed data, eg "23 Files",
and edit out the rubbish - again without pesky interruptions from a dialogue
box.
In this case you would act upon the TextBox_Change events. If the text is
not empty and contains only digits then set it's background to the 'good'
colour and clear the status panel for that box. Otherwise set it to the 'bad'
colour and put a message in the status bar panel for that box. Then do the
same for the other text. Then, if both are ok, enable the calculation buttons.
Otherwise disable them.
By the way, allow leading and trailing spaces in the input. It's annoying
to a user to have to delete spaces which <they> know don't matter. Especially
if the font makes them narrow and they haven't wiped their glasses. But, of
course, take them off before using the number.
This makes for a very unintrusive UI - informative, obvious and with no
interruptions to the user's work flow. There's no harm in keeping the
disablement of alpha/punctuation keys.
Hope this gives you some ideas.
Regards,
Fergus