Custom Text Box go to next Text Box

  • Thread starter Thread starter Guest
  • Start date Start date
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);
}
}
 
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.
 
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);
}
}
 
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);
 
Back
Top