Hi Gurus of Greatness!
I'm working on an WinForms app that has a textbox that allows pasting of CSV text data, and does some formatting on it. I have the formatting I need in place. However, what I end up with is the raw pasted text (CSV) and the formatted text.
How can I intercept the pasted text, do my formatting, then append the text that's already in the textbox?
Here's my Ctrl+V code on the KeyDown event of the textbox:
void txtNote_KeyDown(object sender, KeyEventArgs e)
{
TextBox box = (TextBox)sender;
if (e.Control && e.KeyCode == Keys.V)
{
string[] strtextlines = Clipboard.GetText().ToString().Split(new char[] { '\n' });
strtextlines[0] = strtextlines[0].Replace("\r\n", "");
string strtextheader = "||" + strtextlines[0].Replace(",", "||");
strtextheader = strtextheader + "||\r\n";
string strttextbody = "";
for (int i = 1; i <= strtextlines.Length-1; i++)
{
strtextlines[i] = strtextlines[i].Replace("\r\n", "");
strttextbody = strttextbody + "|" + textlines[i].Replace(",", "|");
strttextbody = strttextbody + "|\r\n";
}
box.Text = box.Text + "\r\n" + strtextheader + strttextbody;
}
}