Programmatically copy and paste text

0 votes
asked Nov 28, 2010 by Gerard (120 points)
edited Nov 29, 2010

Hello! In the terminal emulator component, is there a way to programmatically copy and paste text to and from the Windows clipboard?

I'd like to provide our users with a popup menu that would allow them to copy the selected text to the clipboard, and to paste text from the windows clipboard to the command line.

I don't want to use the MousePasteEnabled option since our users do not like the way the automatic paste on right-click feature works.

1 Answer

+2 votes
answered Nov 29, 2010 by Lukas Pokorny (128,250 points)
edited Nov 29, 2010

Yes, this is possible. Details:

  1. Copy; To get currently selected text from a TerminalControl, call its GetSelectedText method.
  2. Paste; To disable auto-paste, set TerminalControl's MousePasteEnabled property to false. To implement your own paste (in a popup menu), use the control's SendToServer method to send the clipboard text.

Sample code for copy/paste popup menu items event handlers:

    // Copy
    private void copyItem_Click(object sender, EventArgs e)
        string text = terminal.GetSelectedText();
        if (text != null)

    // Paste
    private void pasteItem_Click(object sender, EventArgs e)
        if (Clipboard.ContainsText(TextDataFormat.Text) || Clipboard.ContainsText(TextDataFormat.UnicodeText))
            string text = Clipboard.GetText();
            if (text != null)
commented Nov 29, 2010 by Gerard (120 points)
Thank you very much. That is exactly what I needed to know.