Can I get copy/paste functionality from a C# Console Window?
I am developing a console application in C#, a开发者_如何学Pythonnd was wondering if there was a way to get the "copy-paste" or "mark-paste" functionality into my application, similar or identical to that of the standard Windows command prompt. Is this a wild goose chase or a simple application variable?
I've copied text from the Console window and pasted it into another source many times.
It's there as default in a Console application;
Right click the console border:
Select Edit > Mark:
Drag over the text you want using the mouse (Or use the arrow keys) to select the text you want:
Again, right click on the console border and select Edit > Copy:
From here you can paste it into another application as you would with any other text.
This was taken from a C# Console application and the only code entered was the command to write to the console, no settings were changed.
Hope this helps!
Thank you Sean for making me realize the complete idiocy of this question. Let me be an example to others to not jump on the conclusion train.
Sean pointed out that "copy-paste can be done using cmd.exe's built-in functionality", making me recognize that, yes, absolutely duh, when you run your command line application in Windows it already has this functionality available.
I erred by jumping to conclusions, for I was doing all my initial testing with the DEBUG execution through the IDE, and vshost does not give you that functionality.
A quick "Start Without Debugging" revealed my short-sightedness.
I don't know why this isn't included in any answer, but as Robert H. stated in a comment, this is absolutely useful information, in case you came here by searching for this problem in a VisualStudio environment:
Run a console app in the debugger (F5). You cannot copy or paste. Run it outside the debugger (Control + F5). Now, you can copy and paste.
Worked like a charm for me. Thanks Robert H.!
To clarify, is the default command prompt behavior not working at all for you, or just not how you want it to?
From what I understand, it is the terminal implementation that supplies the copy/paste behavior, and what it provides doesn't match rest of Windows. To change this behavior, you'd have to switch the program that implements the terminal. Here are a couple programs that come up on a google search for "command prompt replacement":
http://www.powercmd.com/
http://sourceforge.net/projects/console/
Of those two, I think one of my friends at work tried "Console". It did enough of what he wanted that he didn't feel the need to keep looking.
If you just want your output for this specific program to work more like the rest of Windows, your other choice is to make it a Windows program.
Edit: Fixed the URL to Console. Was posting to someone's blog that linked to it, before :)
Maybe I am late but there is a shortcut for pasting text in Console Window in c#. Press Alt+Space then 'E' then 'P' and there you have your text pasted in the Console Window
精彩评论