Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to copy code from Visual Studio and paste formatted code to OneNote?

Is there a way to copy code from visual studio (C#) and paste it into OneNote, without losing the formatting?

I was able to do this, but only if I copy from VS, paste to Word, copy from Word, and then paste to OneNote.

like image 844
MedicineMan Avatar asked Apr 23 '09 19:04

MedicineMan


People also ask

How do I paste a code into OneNote?

Add Code Blocks in OneNoteClick the NoteHighlight tab and select a language. In the pop-up window that appears, paste the code and click OK. Highlighted source code will show up on the page. You can change the code style and choose a Box Color around the code.

How do I copy formatting code in Visual Studio?

Go to Tools -> Options. type copy in the search box. Under Text Editor -> Advanced ... Check Copy rich text on copy/cut.


2 Answers

There is fortunately a solution for Visual Studio 2010! Install the Visual Studio 2010 Pro Power Tools extension and copy/paste to OneNote retains syntax highlighting.

like image 50
Jan Roelof Avatar answered Sep 22 '22 17:09

Jan Roelof


This is an option that seems to be disabled by default.

To enable (in VS 2019):

  1. Go to Tools -> Options

  2. type copy in the search box

  3. Under Text Editor -> Advanced...

  4. Check Copy rich text on copy/cut

Visual Studio Options Example

Top copy as formatted

Once the feature is enabled, depending on the target, this may be a two-step process. If, after copying and pasting code, it still appears as unformatted (e.g. if pasting into a web browser), use the approach suggested by marcus, by first pasting into wordpad.exe (start -> run -> type wordpad), then copying the text from within Wordpad again, and pasting into the target application/browser.

like image 29
CJBS Avatar answered Sep 20 '22 17:09

CJBS