[英]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)工具 --> 选项 --> 文本编辑器 --> 高级 --> 在复制/剪切时复制富文本(选中) --> 最大长度(一个非常大的数字)
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.