Custom Text Box go to next Text Box

G

Guest

Custom text box to go to next text box in tab list. When the user types in a
text box and the max length is meet, the focus goes to the next text box in
the tab list. Here is my code so far, but I don't know what to put in the
first parameter of SelectNextControl, noted with a question mark.

class ClassTextBox : System.Windows.Forms.TextBox
{
protected override void OnEnter(System.EventArgs e)
{
base.OnEnter(e);
SelectAll();
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
this.SelectNextControl(?, true, true, true, true);
}
}
 
N

Nicholas Paldino [.NET/C# MVP]

Mike L,

Just pass this for the first parameter, to start at the current control
(since it is assumed you have focus at that point).

Hope this helps.
 
G

Guest

No errors, but the focus does not go to the next control when the max length
is meet.

class ClassTextBox : System.Windows.Forms.TextBox
{
protected override void OnEnter(System.EventArgs e)
{
base.OnEnter(e);
SelectAll();
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);

if (this.Text.Length == this.MaxLength)
{
this.SelectNextControl(this, false, true, true, true);
}
}
}




Nicholas Paldino said:
Mike L,

Just pass this for the first parameter, to start at the current control
(since it is assumed you have focus at that point).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mike L said:
Custom text box to go to next text box in tab list. When the user types
in a
text box and the max length is meet, the focus goes to the next text box
in
the tab list. Here is my code so far, but I don't know what to put in the
first parameter of SelectNextControl, noted with a question mark.

class ClassTextBox : System.Windows.Forms.TextBox
{
protected override void OnEnter(System.EventArgs e)
{
base.OnEnter(e);
SelectAll();
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
this.SelectNextControl(?, true, true, true, true);
}
}
 
T

Tom Porterfield

Mike said:
No errors, but the focus does not go to the next control when the max length
is meet.

class ClassTextBox : System.Windows.Forms.TextBox
{
protected override void OnEnter(System.EventArgs e)
{
base.OnEnter(e);
SelectAll();
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);

if (this.Text.Length == this.MaxLength)
{
this.SelectNextControl(this, false, true, true, true);
}
}
}

Change your code to
this.FindForm().SelectNextControl(this, false, true, true, true);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top