I have a class that inherits the Textbox class. My main goal is to prevent specific keys from being entered into the textfield. Now, I have a solution however I have one issue with it.
this works flawlessly, based on my custom enumerators for the Lparam values of the keys this is able to detect the keydown event of specific keys. Now my issue is being able to prevent that key from entering it's char into the textbox. I thought since I never call the parent/super/base WndProc method the rest of the event would not take place, effectively stopping the key from entering it's data into the field.
Using my logic having the code:
would prevent the textbox from inserting the "+" into the field.
So to allow it I would just simply need to do this:
but this is *NOT* the case. So this either means the message is made after the textbox has processed the keydown OR there is another event (keyup?) when the textbox adds the keychar into the textfield.
NOTES:
I have chosen to do it this way because the Keydown/Keypress/Keyup events in a textbox do not allow you to check the exact key (ie the Return key vs. the numpad Enter key. etc etc the numpad + vs a normal keyboard +)
VB.NET:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Select Case m.Msg
Case WM_KEYDOWN 'on key press
Select Case DirectCast(m.LParam.ToInt32, SSKeys)
Case SSKeys.Enter
MsgBox("Enter from Keyboard pressed")
Case SSKeys.NumpadEnter
MsgBox("Enter from Keypad pressed")
Case SSKeys.Numpad_Add
MsgBox("add from keypad pressed")
Case Else
MyBase.WndProc(m)
End Select
Case Else
MyBase.WndProc(m)
End Select
Using my logic having the code:
VB.NET:
Case SSKeys.Numpad_Add
MsgBox("add from keypad pressed")
So to allow it I would just simply need to do this:
VB.NET:
Case SSKeys.Numpad_Add
MsgBox("add from keypad pressed")
MyBase.WndProc(m) 'call parent method to finish message
NOTES:
I have chosen to do it this way because the Keydown/Keypress/Keyup events in a textbox do not allow you to check the exact key (ie the Return key vs. the numpad Enter key. etc etc the numpad + vs a normal keyboard +)