471,354 Members | 1,212 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Custom Textbox AutoTab

I built 3 textbox classes. The auto tab does not tab to the next control in
the tab list. No errors, and the code steps through
"this.SelectNextControl(this, true, true, true, true);".

What is the code missing, so the auto tab will go to the next control in the
tab list when the max length value is reached?

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

class ClassTextBoxNum : ClassTextBox
{
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (!Char.IsDigit(e.KeyChar) &&
!Char.IsControl(e.KeyChar))
{
e.Handled = true;
}
base.OnKeyPress(e);
}

}

class ClassTextBoxNumTab : ClassTextBox
{
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
{
e.Handled = true;
}
base.OnKeyPress(e);
}

protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);

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

}

Dec 20 '05 #1
2 5944
Hi Cadel,

Thanks for your post.

I am not sure I understand your problem context very well. Can you give
some more detailed description on it?

Currently, after reviewing your sample code snippet, I think the problem
may be that the this.SelectNextControl(this, true, true, true, true)
statement does not work in ClassTextBoxNumTab, yes?

To resolve this problem, I can provide 2 solutions:
1. Use ProcessDialogKey(Keys.Tab) method to simulate the tab key function
2. first find the parent form, then inovke Form.SelectNextControl method.

Sample code snippet listed below:
class ClassTextBoxNumTab : ClassTextBox
{
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
{
e.Handled = true;
}
base.OnKeyPress(e);
}

protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);

if (this.Text.Length == 20)
{
//this.ProcessDialogKey(Keys.Tab); // this is the first solution
this.FindForm().SelectNextControl(this, true, true, true, true); //this
is the second solution
}
}
}
Note: I modified this.MaxLength to 20, so that we can achieve the
limitation ASAP.

These 2 solutions works well on my side. Hope it helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Dec 21 '05 #2
Hi Cadel,

Does my reply make sense to you? Is your problem resolved? Please feel free
to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Dec 27 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Ryan Joseph So | last post: by
1 post views Thread by Sanjay Pais | last post: by
1 post views Thread by rn5a | last post: by
reply views Thread by rn5a | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.