views:

311

answers:

4

I have to turn in a hard copy of some code with an assignment. Is there any way in Visual Studio 2010 to print C# source code with syntax highlighting?

PS: The assignment is solving a math problem, so the choice of language isn't important and the teacher doesn't need to compile and run the program. She just wants to see our approach and results.

+3  A: 

The best way I've found to accomplish this is to copy from Visual Studio and paste into something like MS Word or OpenOffice Writer.

This gives you full source code, with syntax highlighting. You can then print from Word (including adding your intro documentation before the code, etc).

Reed Copsey
Unfortunately this loses the nice word wrap and line numbering that printing from VS gives (which are more important that the syntax highlighting).
280Z28
Depends on what you want. You can setup the printer to keep the syntax highlighting (see Zarembisty's answer) if you need that. I tend to keep my lines short, so the word wrap's rarely an issue for me.
Reed Copsey
+3  A: 

If you go to Options -> Environment -> Fonts and Colors you can change settings to print with syntax highlighting (change 'Show settings for' dropdown to 'Printer'). But you will need to change all the individual settings to match your IDE (I don't know of a way to make it automatic)

Edit: you can use that "Use..." button next to the dropdown to copy settings from the Text Editor

Marek Karbarz
It must be a bug in 2010: it uses the color you have set for Plain Text for all the code, with the exception of the line numbers which use the appropriate setting.
280Z28
you're right - I've done this with VS 2008 (although it seems that by default it was setup to print in color so no changes were necessary) but VS 2010 prints in black and white (except for line numbers) no matter what I try
Marek Karbarz
Also, despite showing fine in the comments in the IDE, it can't print the ∇ character of ∇φ, which makes for some rather "interesting" explanations - time to get out the pen.
280Z28
+4  A: 

Just to let everyone know, unfortunately printing in color was cut from Visual Studio 2010 because of resource constraints. Since we've rewritten the editor from scratch in WPF, we didn't have time to reimplement everything so we had to sacrifice this feature. We will try to implement this in the next version of Visual Studio. For now, copy to clipboard and paste into other app such as Microsoft Word is the recommended solution for printing code with color.

Kirill Osenkov