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
This is an option that seems to be disabled by default.
Go to Tools -> Options
type copy in the search box
Under Text Editor -> Advanced
...
Check Copy rich text on copy/cut
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.