简体   繁体   English

从 MS Visual Studio 复制代码文本并保留源颜色和格式

[英]Copy the code text from MS Visual Studio and keeping the source color and formatting

I used to copy the text of my C# code in a word document to have a backup of my progress.我曾经将我的 C# 代码的文本复制到 Word 文档中以备份我的进度。 Previously the color of the codes (blue, black, green) was kept when I paste it in any text editor program (MS word, WordPad...).以前,当我将代码的颜色(蓝色、黑色、绿色)粘贴到任何文本编辑器程序(MS word、写字板...)中时,代码的颜色会保持不变。 Recently it is not so.最近并非如此。 The format of the text (indentations) is kept but the color unfortunately is just black.文本(缩进)的格式被保留,但不幸的是颜色只是黑色。 That helped me a lot to have previous version of my code on another monitor.这对我在另一台显示器上拥有以前版本的代码有很大帮助。 The codes are displayed just normal in Microsoft Visual Studio but the color is lost when I copy and paste it anywhere else.这些代码在 Microsoft Visual Studio 中正常显示,但是当我将其复制并粘贴到其他任何地方时颜色会丢失。 (I have checked the paste setting of MS word and they are set to keep the formatting of the source. The problem shouldn't be there.) (我已经检查了 MS word 的粘贴设置,它们被设置为保持源的格式。问题不应该存在。)

I use Microsoft Visual Studio Professional 2019.我使用 Microsoft Visual Studio Professional 2019。


Edit and answer:编辑并回答:

The problem was that although the "cope rich text on copy/cut" option was checked, my code exceeded the maximum character count for this property.问题是,虽然选中了“在复制/剪切时处理富文本”选项,但我的代码超过了该属性的最大字符数。 It was solved by changing the "Max Length" to a very big number.它是通过将“最大长度”更改为一个非常大的数字来解决的。 Default is 10240 and I added three more zeros.默认值为 10240,我又添加了三个零。

Therefore the path to the solution is:因此解决方案的路径是:

Tools --> options --> Text Editor --> Advanced --> Copy rich text on copy/cut (checked) --> Max Length (a very big number)工具 --> 选项 --> 文本编辑器 --> 高级 --> 在复制/剪切时复制富文本(选中) --> 最大长度(一个非常大的数字)

在此处输入图像描述

You need to check the options "Copy rich text on copy/cut" and "Use accurate classification" in the Text Editor->Advanced settings dialogue within Visual Studio 2019.您需要在 Visual Studio 2019 的“文本编辑器”->“高级设置”对话框中选中“在复制/剪切时复制富文本”和“使用准确分类”选项。

设置中的示例屏幕截图

If you download Notepad++ you can use that as a backup medium.如果您下载 Notepad++,您可以将其用作备份媒体。

Copy and paste your code into Notepad++, select "Language" at the top, hover over "C" and select "C#".将代码复制并粘贴到 Notepad++ 中,select 顶部的“语言”,hover 的“C”和 select“C#”。

Once this is done, depending on how your Notepad is configured you should have the key functions etc in a different colour.完成此操作后,根据记事本的配置方式,您应该拥有不同颜色的按键功能等。

If you don't, do the following:如果不这样做,请执行以下操作:

Settings --> Style Configurator --> Click on C# --> Click "Default" --> and set "Foreground Colour" to a colour of your choice.设置 --> 样式配置器 --> 点击 C# --> 点击“默认” --> 并将“前景色”设置为您选择的颜色。 In my example I have chosen blue, which will look something like this:在我的示例中,我选择了蓝色,看起来像这样:

在此处输入图像描述

Some months back the default action of MSVS is to copy the text with syntax formatting so I didn't have a problem but was a bit miffed when only plain text is copied when I copy too much.几个月前,MSVS 的默认操作是使用语法格式复制文本,所以我没有遇到问题,但是当我复制太多时只复制纯文本时,我有点恼火。

I think there was a recent update where I discovered that only plain text is being copied.我认为最近有一个更新,我发现只有纯文本被复制。

I tried many extensions (Copy as HTML, Syntax Highlighting Pack, Copy with Line Number) to no avail.我尝试了许多扩展(复制为 HTML、语法突出显示包、使用行号复制)均无济于事。 Google search could not give me the answer.谷歌搜索无法给我答案。

Then I found by typing "copy" into the MSVS search bar that there is this new option:然后我通过在 MSVS 搜索栏中输入“复制”发现有这个新选项:

Text Editor -> Advanced -> Copy rich text on copy/cut:文本编辑器 -> 高级 -> 在复制/剪切时复制富文本:

Max length: 10240最大长度:10240

? ? Use accurate classification使用准确的分类

I have no idea what Use accurate classification means.我不知道使用准确分类是什么意思。

Maybe the option was there all along just that I didn't know about it.也许选项一直存在,只是我不知道。

Only by google search of "Use accurate classification" could I find this post.只有通过谷歌搜索“使用准确分类”才能找到这篇文章。

Still no description of what "Use accurate classification" is about.仍然没有描述“使用准确分类”是关于什么的。

Anyway happy that it is finally working now.无论如何,很高兴它现在终于可以工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将Visual Studio中的所有源代码导出到文本文件中? - How to export all the source code from Visual Studio into a text file? 如何将代码从 Visual Studio 复制到 MS Word,每个突出显示都完全一样? - How to copy code from Visual Studio to MS Word with EVERY highlight exactly as it is? 从Visual Studio复制/粘贴到浏览器,且格式保持不变 - Copy/paste from Visual Studio to browser with formatting intact 在文本中格式化 C# 代码,如 Visual Studio - Formatting C# code in text, like Visual Studio 如何阻止 Visual Studio 自动格式化代码的某些部分? - How to stop Visual Studio from auto formatting certain parts of code? 如何防止 Visual Studio 格式化特定代码? - How to prevent Visual Studio from formatting specific code? 是否可以从 Visual Studio 复制代码并将格式化的代码粘贴到 OneNote? - Is it possible to copy code from Visual Studio and paste formatted code to OneNote? Visual Studio Code 中的 Formatting.aspx 代码 - Formatting .aspx code in Visual Studio Code 从 Visual Studio 2017 内部查看内置 function 的源代码? - View source code of built in function from inside Visual Studio 2017? 如何从Visual Studio中下载的包中查看源代码 - How to view the source code from downloaded packages in Visual Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM