我可以从 C# 控制台窗口获得复制/粘贴功能吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2210245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:27:51  来源:igfitidea点击:

Can I get copy/paste functionality from a C# Console Window?

c#command-lineconsoleconsole-applicationcopy-paste

提问by Simpleton

I am developing a console application in C#, and 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?

我正在用 C# 开发一个控制台应用程序,想知道是否有办法将“复制粘贴”或“标记粘贴”功能添加到我的应用程序中,与标准 Windows 命令提示符的功能类似或相同。这是野鹅追逐还是简单的应用程序变量?

采纳答案by Simpleton

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.

Sean 指出“可以使用 cmd.exe 的内置功能完成复制粘贴”,这让我认识到,是的,绝对是,当您在 Windows 中运行命令行应用程序时,它已经具有此功能。

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.

我错误地得出结论,因为我是通过 IDE 对 DEBUG 执行进行所有初始测试的,而 vshost 没有为您提供该功能。

A quick "Start Without Debugging" revealed my short-sightedness.

一个快速的“开始而不调试”暴露了我的短视。

回答by Merlyn Morgan-Graham

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/

据我了解,提供复制/粘贴行为的是终端实现,它提供的内容与 Windows 的其余部分不匹配。要更改此行为,您必须切换实现终端的程序。以下是 Google 搜索“命令提示符替换”时出现的几个程序:
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.

如果您只是希望此特定程序的输出更像 Windows 的其余部分那样工作,那么您的另一个选择是将其设为 Windows 程序。

Edit: Fixed the URL to Console. Was posting to someone's blog that linked to it, before :)

编辑:修复了控制台的 URL。之前发布到链接到它的某人的博客:)

回答by Jamie Keeling

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:

右键单击控制台边框:

Step 1

第1步

Select Edit > Mark:

选择编辑 > 标记:

Step 2

第2步

Drag over the text you want using the mouse (Or use the arrow keys) to select the text you want:

使用鼠标(或使用箭头键)拖动您想要的文本以选择您想要的文本:

Step 3

第 3 步

Again, right click on the console border and select Edit > Copy:

再次,右键单击控制台边框并选择编辑 > 复制:

Step 4

第四步

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.

这是从 C# 控制台应用程序中获取的,输入的唯一代码是写入控制台的命令,没有更改任何设置。

Hope this helps!

希望这可以帮助!

回答by z00l

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:

我不知道为什么这不包含在任何答案中,但正如Robert H.在评论中所说,这是绝对有用的信息,以防您通过在VisualStudio 环境中搜索此问题来到这里:

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.

在调试器 (F5) 中运行控制台应用程序。您不能复制或粘贴。在调试器之外运行它 (Control + F5)。现在,您可以复制和粘贴。

Worked like a charm for me. Thanks Robert H.!

对我来说就像一种魅力。谢谢罗伯特 H.!

回答by Raza

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

也许我迟到了,但是在 c# 的控制台窗口中有一个粘贴文本的快捷方式。按 Alt+Space 然后按 'E' 然后按 'P' 就可以在控制台窗口中粘贴文本了