Extending the TextBox consist of making a control and having it inherit
from System.Windows.Forms.TextBox instead of System.Windows.Forms.Control.
In its KeyPress event you can check if [Enter] was pressed and send [Tab]
instead. You should also restrict the TextMode property to SingleLine
because this extended TextBox will never be able to hold multiline text.
Then you need to use this control in place of the TextBox control.
HOWEVER, there is a much bigger problem. If they do not learn to hit
[Tab] instead of [Enter] to move to the next control then you will have to
extend EVERY control (MS controls and 3rd party controls) to this
behavior. You will basicly loose all the [Enter] key functionality of all
your controls. Look at the multiline problem above. This is total madness.
Every control expects [Tab] to move to a the next control. This is the
normal behavior in windows programs. Do you see the problem you will
create if you allow this to persist. The cost developement, debugging,
supporting, ... EVERYTHING goes skyward very quickly. This [Enter]
extension may seem cute on the form you are working on now BUT they will
expect this functionality on EVERY form and EVERY application you design.
Start to add ComboBoxes, CheckBoxes, ListBoxes, DataGrids, other MS and
3rd party controls that deal with [Enter] differently than they deal with
[Tab]. You will basicly loose all the [Enter] key functionality of all
your controls. Look at the multiline problem above. Do you see what you
are getting yourself into.
They must upgrade their skills when moving to a new system. Hitting [Tab]
instead of [Enter] is not rocket science. They can't expect to move to a
new system and do everything the old way.
Robby
PS. hummm ... I just though of something. You could KeyPreview on the
form and send [Tab] when enter is pressed. That would simplify it. But
it will lead to other problems. Don't let them know that. Press the
expensive to develope and support line I rambled on about above. Ramble
on about the increased cost for current and future developement of the
system.
End Users: Can't live with them, can't get rid of them with out people
asking lots of questions.
################
TheNortonZ said:
Oh, but just in case I do decide to extend it, what do I override to get
this to happen?
STom
Robby said:
Having the TextMode set to SingleLine will cause this behaviour. Users
should hit the [Tab] key to move to the next field. You can extend the
TextBox class so that it responds to [Enter] as if [Tab] was hit. I
think it would be a better idea simply to get them to start using [Tab]
as this is the norm for Windows apps.
Robby
I have a requirement where when the user is in an edit field, they
should be able to hit Enter(return).
When I do this, my system makes a noise as though an illegal entry has
been made.
Is there a reason it is doing this and is there a way to change it?
Thanks.
STom