Solved

Formatting a Textbox

Posted on 2006-10-27
3
196 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 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now