0 votes
by (120 points)
edited

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
by (148k points)
edited

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)
            Clipboard.SetText(text);
    }

    // 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)
                terminal.SendToServer(text);
        }
    }
by (120 points)
Thank you very much. That is exactly what I needed to know.
...