How to stop DrawText from underlining alt characte

2019-09-25 07:01发布

问题:

I'm using DrawText to draw text onto a DBGrid canvas. The text comes from the database. But when the string contains an ampersand (&) it treats it as an alt shortcut and underlines it.

For example, what should be

Wool & Silk

winds up being

Wool _Silk

How do I stop this behavior?

回答1:

Suppress prefix handling with the DT_NOPREFIX flag. This is the way forward if you know you do not want any prefixes drawn.

If you want to draw text with both prefixes and ampersand, you can escape the ampersand by doubling it up. So pass && when you want a single ampersand.

You can find all this information, and more, in the documentation.