hey all,,
I have this picture to be more clear:
http://img846.imageshack.us/img846/5996/95028490.png

My idea is when I paste (ctrl+v) for example this number :
4111111111111111

it would automatically paste them in textboxes one by one in order!

so txtBox1 will contain : 4111
txtBox2 : 1111
txtBox3 : 1111
txtBox4 : 1111

the automation of inserting credit card's number will ease so much
so that user will not work so hard to cut & paste each four digits!

so any suggestion of doing auto-fill inside textboxes..?

2)if I am already in txtBox4 and want to delete back with the key "BackSpace/Return"
after deleting txtBox4's content and clicking one more time the "RETURN' key it would move to txtBox3 and so on until cursor gets to txtBox1...

thanks.

Recommended Answers

All 5 Replies

In the onTextChanged event of the first text box (or all of them if you want to be really user friendly) split the string into 4 substrings, each 4 characters long. Then just paste each substring into the right text box.
I wouldn't use the return key as a 'move backward' command. It isn't very obvious. I'd expect the return key to move the cursor forward if not submit the form. Code up the backspace key event so that if the length of the text box is zero and the backspace is pressed, focus moves to the previous text box.

something like this should do the trick...

Private Sub TextBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
		If e.Control AndAlso e.KeyCode = Keys.V Then
			Dim s As String = My.Computer.Clipboard.GetText.Trim
			If s.Length = 16 Then
				TextBox1.Text = s.Substring(0, 4)
				TextBox2.Text = s.Substring(3, 4)
				TextBox3.Text = s.Substring(6, 4)
				TextBox4.Text = s.Substring(9, 4)
				e.SuppressKeyPress = True
			End If
		End If
	End Sub

	Private Sub TextBox4_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox4.KeyDown, TextBox3.KeyDown, TextBox2.KeyDown
		If e.KeyCode = Keys.Back AndAlso CType(sender, TextBox).TextLength = 0 Then
			Me.SelectNextControl(CType(sender, TextBox), False, True, False, False)
		End If
	End Sub

GeekByChoiCe, thank you very much for your help..

I loved the second solution:) it is really so nice and tricky!

credits to you:)

I just forgot to let you know to fix the indexes/lengths in Substring function

Private Sub txtOne_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtOne.KeyDown
        If e.Control AndAlso e.KeyCode = Keys.V Then
            Dim s As String = My.Computer.Clipboard.GetText.Trim
            If s.Length = 16 Then
                txtOne.Text = s.Substring(0, 4)
                txtTwo.Text = s.Substring(4, 4)
                txtThree.Text = s.Substring(8, 4)
                txtFour.Text = s.Substring(12, 4)
                e.SuppressKeyPress = True
            End If
        End If
    End Sub

Yeah that could be.
But anyway, your problem is solved? then mark the thread as solved please =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.