Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Formatting a Textbox

Posted on 2006-10-27
3
Medium Priority
?
204 Views
Last Modified: 2010-04-23
Hi all,

I have a textbox on my form and I would like the user to enter 4 numbers into it and have the textbox automatically format it to xx/xx as they are typing. I have tried using the below code but when I do once the first two numbers have been typed the cursor is moved back to the start of the box rather than after the "/"

If txtboxExp.Text.Length = 2 Then
       txtboxExp.Text = txtboxExp.Text & "/"
End If

Can someone let me know and easy way of creating a custom format for a textbox like this.
Thanks
0
Comment
Question by:kiranboi
3 Comments
 
LVL 17

Accepted Solution

by:
ZeonFlash earned 2000 total points
ID: 17818888
Try this:

            If txtboxExp.Text.Length = 2 Then
                  txtboxExp.Text = txtboxExp.Text & "/"
                  txtboxExp.SelectionStart = txtboxExp.Text.Length
            End If
0
 

Author Comment

by:kiranboi
ID: 17818927
Perfect.

Thanx
0
 
LVL 5

Expert Comment

by:xersoft
ID: 17818938
If you are using .net 2.0 you can use the masked edit textbox and set the mask to "00/00" Does that provide what you are after?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question