I have a .net application which includes search screen which has a panel with has three text boxes, each with a varying character lengths.
What I'd like to do is capture when the paste command when invoked from the first box and paste my clipboard into the three boxes.
This functionality is similar to many modern applications accepting input for serial keys and phone numbers.
As far as I can find there is no other sensible way of doing this than to capture the WM_PASTE event.
Derive a class from TexBox and implement this method:
Then put three of those custom controls on your form, and assign the
OnPaste
event on all three textboxes to the same method, in this case I called ittextPasted()
:Since you implied "like a serial", I guessed you want the pasted string to be split among the textboxes. The code above is not perfect for that (try pasting a single space into the third text box after entering data manually in all three, so it would be nice if you knew in which textbox the text was pasted, for example by altering the event's parameters and that way sending the sender with it), but it basically works and I guess you can figure out the rest (you could use the
Tag
property to identify the textbox).You could increase the character limit of the boxes and register for
TextChanged
and if the pasted (or typed) text is longer jump/cut to the nextTextBox
.you can get the captured text
String txt = Clipboard.GetText();
and place it in the "Text" property of the other textboxCapture the paste event:
Then, access the Clipboard object to get the desired text.
You can bind key down event, and when you get
Ctrl + V
orCtrl + v
, you update the value of the three textbox with value in the clipboad. You can do this onTextChanged
event off first text box.