开发者

GDI+: Draw underlined space with DrawString

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 st开发者_如何学JAVAring 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.


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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜