简体   繁体   中英

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. Previously the color of the codes (blue, black, green) was kept when I paste it in any text editor program (MS word, WordPad...). 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. (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.)

I use 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.

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.

设置中的示例屏幕截图

If you download Notepad++ you can use that as a backup medium.

Copy and paste your code into Notepad++, select "Language" at the top, hover over "C" and 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. 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.

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

Text Editor -> Advanced -> Copy rich text on copy/cut:

Max length: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM