Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 135,915 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,584 people online right now. Registration is fast and FREE... Join Now!




Masked textbox

 
Reply to this topicStart new topic

Masked textbox

lookfahim
19 May, 2008 - 11:46 PM
Post #1

New D.I.C Head
*

Joined: 31 Mar, 2008
Posts: 4

well i am using masktextbox control for phone entry .i have problem that when user press the enter key witout filling data in masked textbox then it accept change and coursor go to next control ...but when user enter the data then data must be 10 character....i have done this but it didn't work when user insert less than specified range and press enter then it go to next control...i dont wnat this ...if user entering the data user have to input data to that specified range ...i am pasting code kindly suggest me.
CODE

private void maskedTextBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((int)e.KeyChar == 13)
            {
                if (maskedTextBox1.Text == "")
                {
                    textBox2.Focus();
                }
                else if ((maskedTextBox1.TextLength > 10) || (maskedTextBox1.TextLength < 10))
                {
                    MessageBox.Show("Data must be 5 character");
                    maskedTextBox1.Focus();
                }
                else
                {
                    textBox2.Focus();
                }
            }

User is offlineProfile CardPM
+Quote Post

zakary
RE: Masked Textbox
20 May, 2008 - 03:40 AM
Post #2

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 404



Thanked: 6 times
Dream Kudos: 175
My Contributions

csharp
 
private void maskedTextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
// this checks to see if maskedTextBox1 length is 10
if (maskedTextBox1.TextLength != 10)
{
MessageBox.Show("Data must be 10 character");
maskedTextBox1.Focus();
}
else // if not 10
{
textBox2.Focus();
}
}

User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 07:58AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month