Search code examples
delphidrawingdrawtext

How to stop DrawText from underlining alt characters?


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?


Solution

  • 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.