1

Hallo,

i want to draw a justified text in GDI+. When this text is underlined I have a problem, with the DrawString method:
- If you give to this method a string with a whitespace and the format underlined, it draws nothing, because the space has no width.
- If you have a justified text the maybe spaces are wider than normal.

I found no solution to draw a underlined space with a special width.

Thanks for your help.

Sperl Christoph
  • 73
  • 1
  • 1
  • 6

2 Answers2

2

GDI+ will draw the underline up to the trailing whitespace, and this is normally a desirable thing compared to GDI TextOut's behavior; but if you append any invisible non-whitespace character to the string you pass to DrawString (like U+200B zero width space or even a control character like U+007F), then the last character will no longer be the space, and all spaces are underlined. This is less brittle than trying to calculate the line length yourself.

Dwayne Robinson
  • 2,034
  • 1
  • 24
  • 39
0

This doesn't particularly surprise me. That's the behavior I would expect. GDI+ will draw the underline as expected for spaces that appear in-line with a string of text. The problem is, a string that contains only whitespace has no length, and thus doesn't get underlined.

So, the question is, why do you need to draw underlined white space? What's wrong with DrawLine?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • Hallo, thank you for the answer. The reason, why I need to underline white spaces is the following: I have something like my own edit-field. In this field I can type letters and so on. In this edit-field you can also make some formatting definitions like alignment. For example alignment justified needs to print all words in my edit-field separatly. So I calculate the width of the space and calculate the position of the words. If the text should be underlined, of course the space between the text should also be underlined. – Sperl Christoph Mar 30 '11 at 16:33