Question Auto Fill TextBoxes when Paste

eawedat

Member
Joined
Nov 20, 2011
Messages
8
Programming Experience
1-3
hey all,,
I have this picture to be more clear:
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.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,171
Location
Sydney, Australia
Programming Experience
10+
Number 2 is quite easy. You simply handle the KeyDown event of the TextBox and, when you trap the key of interest, do whatever is appropriate. For information on keyboard events, follow the Blog link in my signature.

The first one is similar but more difficult. Rather than handling an event, which there isn't for pasting, you need to override a WndProc method. You can either use a standard TextBox and then use an object derived from NativeWindow to hook into the WndProc method. It's not as complex as it sounds but I'd probably not go that way. Instead, you should define your own class that inherits TextBox. Once you build your project you can then do into the designer code for your form and change each regular TextBox to your new type. In that class, you will override the WndProc method and trap the WM_PASTE message, when the message is received you can do whatever is appropriate. You can check out an example of a derived TextBox at the link below. Conincidentally, it even traps that same message.

Numeric Text Box
 

eawedat

Member
Joined
Nov 20, 2011
Messages
8
Programming Experience
1-3
thank you jmcilhinney :)
actually I got some solution for the first issue,, which is when pasting (clicking ctrl+v) with keyDown's event. I should Split the 16 digits into 4 digits each. and send them to the appropriate textbox.
 
Top Bottom