MaskedTextBox KeyEvents problems
Basically I have two maskedTextBoxes--lets say mA and mB--and when a user makes a change to mA, it transfers all the properties(mask, text, selectstart, etc) to mB, transfers control to mB, and then sends the same key to mB and not modifying mA. The user then finishes the changes and the new values of mB are transfered back to mA and a history record is created showing the field was updated.
Anyway, my problem is I first did it on the keyPress event for a textbox and it worked fine. When I switched to the maskedTextBox however, setting e.handled = true did not prevent the value from being placed into the first box as it had with a textbox. I checked and the text is still blank at the keypress event but even with e.handled set to true, keyUp gets called and by then the text is modified.
I decided then to move it to the keyDown event and use e.SuppressKeyPress which worked. But that caused the problem of having the arrow keys count as a keyDown and triggered it to transfer control to the update maskedtextbox. I looked around and found that setting the e.isInputKey = false in the previewKeyDown event for arrows should work. I tried and nothing changed then I realized that the e.IsInputKey is already false going into the PreviewKeyDown event, yet keyDown still runs (keyPress and keyUp do not however).
I know I could check for arrow keys in the keydown event or just use a different control, but I was just trying to understand what it's doing. I haven't been able to find any documentation saying the maskedTextBox events should act different from a textBox. If anyone could explain something I'm doing/assuming that's wrong or point me to some documentation, that would be great.
-I'm using VB2008 Express and .Net 3.5
Re: MaskedTextBox KeyEvents problems
Welcome to the forums. :wave:
My first question would be why did you move to a MaskedTextbox?
Re: MaskedTextBox KeyEvents problems
I decided to use a MaskedTextBox because it is similar to what was in place in the old software and I haddn't used them before but it seemed like a pretty simple, straight forward way format phone numbers (___) ___-____ and tax rate _.__% and such. It has since become anything but straightforward and I would like to know why instead of just abandoning the idea and moving on.