Sandwich the code with tag <pre lang="???"/> "Wrap in PRE block" automates it. Be careful using angular brackets, escape them with HTML entities < > when using "allow HTML". Another common mistake is misusing "Ignore HTML in text (good for code snippets)" — un-check it before posting.
Another common problem is wrapping. You should make sure long lines of the code is not wrapped at the right bound of the editing control. Is this rule is observed, source code lines are considered to be reasonable short.
I outlined only how to avoid most common mistakes.
See also:
http://www.codeproject.com/info/Submit.aspx[
^]. Not all delicate formatted aspects are described in this article. Basically, you need to understand CodeProject escaping and be well familiar with HTML formatting. Pay attention for the chapter "Syntax colourisation".
—SA