473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Auto tab

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.

Nov 17 '05 #1
5 7333
Mike L,

What do you mean when the field reaches the max limit? Do you mean a
text field? If that is the case, then you have to check when the text
changes (through the TextChanged event) and when you reach the max limit for
the textbox, you can call the GetNextControl method on the textbox, and then
set the focus on that (through the Focus method).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike L" <Ca***@nospam.nospam> wrote in message
news:AE**********************************@microsof t.com...
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.

Nov 17 '05 #2
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
"Mike L" <Ca***@nospam.nospam> wrote in message
news:AE**********************************@microsof t.com...
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.

Nov 17 '05 #3
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]
- mv*@spam.guard.caspershouse.com

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:e0*************@TK2MSFTNGP12.phx.gbl...
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
"Mike L" <Ca***@nospam.nospam> wrote in message
news:AE**********************************@microsof t.com...
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.


Nov 17 '05 #4
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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:ef**************@TK2MSFTNGP09.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote in message news:e0*************@TK2MSFTNGP12.phx.gbl...
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
"Mike L" <Ca***@nospam.nospam> wrote in message
news:AE**********************************@microsof t.com...
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.



Nov 17 '05 #5
Your answer gave me the direction I needed.

With my own modification here is the best solution for my problem.

On TextChanged on the textbox, check the text length to the maxlenght, if
equal then perform code.

private void txtDealerNum_TextChanged(object sender, System.EventArgs e)
{
if (txtDealerNum.Text.Length == txtDealerNum.MaxLength)
{
frmDealerSearch f = new frmDealerSearch(this);
if( f.ShowDialog() == DialogResult.Cancel )
{
txtDealerNum.Focus();
}
else
{
txtLicNum.Focus();
}
}
}


"Ignacio Machin ( .NET/ C# MVP )" wrote:
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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:ef**************@TK2MSFTNGP09.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote in message news:e0*************@TK2MSFTNGP12.phx.gbl...
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
"Mike L" <Ca***@nospam.nospam> wrote in message
news:AE**********************************@microsof t.com...
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.



Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Manlio Perillo | last post by:
Hi. This post follows "does python have useless destructors". I'm not an expert, so I hope what I will write is meaningfull and clear. Actually in Python there is no possibility to write code...
1
by: Glabbeek | last post by:
I'm changing the layout of my site. Instead of using tables, I will use DIVs. It's working fine, except for 1 thing: In IE6 some DIVs are not the correct width. Mozilla and Opera are showing the...
5
by: Robert Downes | last post by:
I'm using the following in a page that I'm testing in Mozilla: p.actionLinkBlock {border: 1px #000000 dashed; padding: 0.2cm; width: auto} But the dashed border is extending to the right-edge...
20
by: Vijay Kumar R. Zanvar | last post by:
Hello, Unlike register, auto keyword can not be used to declare formal parameter(s). Is there any specific reason for this? Kind regards, Vijay Kumar R. Zanvar
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
5
by: Samuel | last post by:
Hi, I am running into a problem of mixing UICulture = auto and allowing users to select culture using a dropdown list. I am detecting a querystring, "setlang", and when found, setting the...
5
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if...
22
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly...
2
by: Piotr K | last post by:
Hi, I've encountered a strange problem with Firefox which I don't have any idea how to resolve. To the point: I've <divelement with a style "height: auto" and I want to retrieve this value...
21
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.