Hi,
I'm creating a enhance textbox control that can accept only numerical value. To do so, I've created a new user control that inherit the textbox properties and added my own code.
When the return key is hit, I want to focus to be pass to the next control. I added the following code in my control class but the SelectNextControl method does not appear to work. I used the step by step debugging method and everything work perfectly except that the next control is not selected. I think that it has something to do with the IsInputKey method but I don't really know what to do about it. The escape key work fine, but the other keys doesn't work.
Note : There is a least 2 controls on the test form with the tabstop property set to true and a different tabIndex.
Private
Sub ctrlDigitBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown Select Case e.KeyCode Case Windows.Forms.Keys.Return, Windows.Forms.Keys.Entere.Handled =
Truee.SuppressKeyPress =
True Me.SelectNextControl(Me, True, True, True, True) Case Windows.Forms.Keys.Escapee.Handled =
Truee.SuppressKeyPress =
True Me.Text = EngFormat(MyValue, MyNbDigit, MyEngThreshold) Me.Select(0, Me.Text.Length) Case Windows.Forms.Keys.Downe.Handled =
Truee.SuppressKeyPress =
True Me.SelectNextControl(Me, True, True, True, True) Case Windows.Forms.Keys.Upe.Handled =
Truee.SuppressKeyPress =
True Me.SelectNextControl(Me, False, True, True, True) End Select End Sub
SelectNextControl method
Priya RV
Really strange. I would have expected that to work, just like you. Maybe its a problem to execute this inside of an event handler. But here is an alternative:
SendKeys.Send("{TAB}") to move to the next control and SendKeys.Send("+{TAB}") to move to the previous.
--
SvenC
aus82
Thanks,
I thought of that but did not try it yet. I don't really like that idea because the way I see it, is that I send a special key (return) to the control and I don't know what's going on with it, and to fixe the problem I'm gonna send an other special key (TAB) to the control. It may result in unexpected behavior. I'll see what it does.
Zubair Masoodi
The 'form' is not really part of the controls collection so doesn't have a tab stop, so doesn't have a 'next' control. Did you try:
Me.SelectNextControl(Me.ActiveControl, True, True, True, True)
This seems to work for text boxes, check boxes, etc.
brent.xml
Just be sure to use a simple Send, not SendWait. With Send you simple put the next message in the queue which will be processed some time after the KeyDown event finished.
Actually I expect the SelectNextControl to do something similar, as most (if not all) of the control communication is through messages.
--
SvenC
Randy Galliano
Never found what was wrong with my method, but the sendkey(tab) work fine.
Thanks