OnKeyDown in a class derived from
The new TextBox has several functions, one of which is to only allow a valid decimal (unsigned) value to 2 decimal places. All is well and decimal places are added if necessary - unless the
MaxLength is exceeded when the formatting is done in
I figured the easiest way would be:
If the key pressed is a number then build the final string in memory, check the length of that against
MaxLength and supress the key press if it would exceed
The problem is getting a char or string value from any of the
KeyEventArgs properties if the number pad is used. Casting or converting to
char returns a, b, c ...
if (e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9)
digit = Convert.ToChar(e.KeyCode - 48);
digit = Convert.ToChar(e.KeyCode);
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
modified on Tuesday, July 29, 2008 7:18 PM
General News Suggestion Question Bug Answer Joke Praise Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.