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

发布于 2024-08-20 02:17:39 字数 107 浏览 4 评论 0原文

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

情独悲 2024-08-27 02:17:39

我已多次从控制台窗口复制文本并将其粘贴到另一个源中。

它在控制台应用程序中默认存在;

右键单击控制台边框:

Step 1

选择编辑 >标记:

Step 2

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

Step 3

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

Step 4

从这里您可以将其粘贴到另一个应用程序中,就像粘贴任何其他文本一样。

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

希望这有帮助!

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

Select Edit > Mark:

Step 2

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

Step 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.

Hope this helps!

冰火雁神 2024-08-27 02:17:39

谢谢肖恩让我意识到这个问题完全是愚蠢的。让我为其他人树立榜样,不要跳上结论列车。

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

我错误地草率下结论,因为我是通过 IDE 使用 DEBUG 执行进行所有初始测试,而 vshost 不提供该功能。

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

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.

江心雾 2024-08-27 02:17:39

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

在调试器 (F5) 中运行控制台应用程序。您无法复制或粘贴。
在调试器外部运行它(Control + F5)。现在,您可以复制并粘贴。

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

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.!

鹿童谣 2024-08-27 02:17:39

澄清一下,默认的命令提示行为是否根本不适合您,或者只是不符合您的要求?

据我了解,终端实现提供了复制/粘贴行为,并且它提供的功能与 Windows 的其余部分不匹配。要更改此行为,您必须切换实现终端的程序。以下是在谷歌搜索“命令提示符替换”时出现的几个程序:

http://www.powercmd.com/

http://sourceforge.net/projects/console/

我认为这两个我的一位工作朋友尝试了“控制台”。它已经满足了他想要的一切,他觉得没有必要继续寻找。

如果您只是希望该特定程序的输出更像 Windows 的其余部分,那么您的另一个选择是使其成为 Windows 程序。

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

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 :)

滥情哥ㄟ 2024-08-27 02:17:39

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文