TextBox Control changing text

usman.pak

New member
Joined
Mar 18, 2007
Messages
4
Programming Experience
Beginner
I have problem with textbox masking
i want to add "-" sign when textbox text length is 2 but when i do that the cursor comes in the start how i over com that thing
Code

dim str as string = "-"

Text Box Change Event
if txtbox.text.length =2 then
txtbox.text = txtbox.text & str
end if

but when ever i try to do that the cursor in the textbox comes in the start
how i slove this problem.
 
use the select sub
VB.NET:
Sub tbChanged()
dim i as int 
dim str as string = "-"
if txtbox.text.length =2 then 
txtbox.text = txtbox.text & str
TextBox1.Select(3,0)
end if

However in .net 2005 there is a masked texbox control where it would be much better to use. If In 2003 I would look online for a masked texbox control.
 
TextBox Control

Thanks alot vinnie881

your code realy help but no i am in other problem when i press back space
its not remove any thing in the text box becasue of the code

Dim str As String = "-"
If txtPid.Text.Length = 2 Then
txtPid.Text = txtPid.Text & str
txtPid.Select(3, 0)
the lenght is 2 and the textchage event run and i am not able to remove the text what can i do Please help me.
 
try this
VB.NET:
dim str as string = "-"

Text Box Change Event
if txtbox.text.length =2 and not Microsoft.VisualBasic.InStr(txtbox.text,"-",CompareMethod.Binary) = 2 then
txtbox.text = txtbox.text & str
TextBox1.Select(3,0)
end if
 
Back
Top