Hi,
You are right , I missed it
Also to notice is that he should be looking only for TextBox instances , if
a combobox appear it should be ignored altogether.
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Nicholas Paldino said:
Ignacio,
You should replace that loop with a call to the GetNextControl method
on the Control that sends the event. It's much easier.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Ignacio Machin ( .NET/ C# MVP ) said:
Hi,
I don;t remember seeing this feature in the framework, so you most
probably will have to implement it. It's easy you would have to use a
KeyPress handler (or another event that fires when a key is pressed) and
check if the length of the text vs the size, if needed move to the next.
What I would do is I would create a handler that will dynamically be
assigned to the "next" control:
This is a very basic struct, just to give you an idea:
EventHandler moveNext = new EventHandler ( TheMethod );
form_load( ... )
firstControl.KeyPress += moveNext;
void TheMethod( object sender , ... )
{
TextBox cur = (TextBox) sender;
if ( cur.Text.Lenght == cur.MaxLength )
{
cur.KeyPress -=moveNext ;
// get the next one, maybe this can be improved
foreach( Control c in Controls )
if ( c.TabIndex == cur.TabIndex+1 ) //gotcha
c.KeyPress += moveNext ;
}
}
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
This is for a Win form.
When the field reaches the max limit I want the cursor to go to the next
field.
Saving the user from pressing the tab key.