private void textBoxCommand_TextPasted(object sender, ClipboardEventArgs e) { if (e.ClipboardText.Contains("\n")) { e.Handled = true; // Get current text, insert at caret and process, leave any trailing line unpasted StringBuilder currText = new StringBuilder(textBoxCommand.Text); currText.Insert(textBoxCommand.SelectionStart, e.ClipboardText); string[] parts = Regex.Split(currText.ToString(), @"(?<=[\n])"); foreach (string line in parts) { if (line.EndsWith("\n")) { AddInput(line.TrimEnd()); } else { if (String.IsNullOrWhiteSpace(line)) { AddInput(line); textBoxCommand.Text = String.Empty; } else { textBoxCommand.Text = line; textBoxCommand.SelectionStart = line.Length; } } } } }
protected override void WndProc(ref Message m) { bool handled = false; if (m.Msg == WM_PASTE) { EventHandler <ClipboardEventArgs> evt = TextPasted; if ((evt != null) && Clipboard.ContainsText()) { ClipboardEventArgs args = new ClipboardEventArgs(Clipboard.GetText()); evt(this, args); handled = args.Handled; } } if (!handled) { base.WndProc(ref m); } }
protected override void WndProc(ref Message m) { bool handled = false; if (m.Msg == WM_PASTE) { EventHandler<ClipboardEventArgs> evt = TextPasted; if ((evt != null) && Clipboard.ContainsText()) { ClipboardEventArgs args = new ClipboardEventArgs(Clipboard.GetText()); evt(this, args); handled = args.Handled; } } if (!handled) { base.WndProc(ref m); } }