Split paragraph into lines based on width in pixels
-
I need to split a paragraph into lines based on a given width in pixels. The idea being that as a user resizes the window, they can see more or less of the paragraph as the window is made wider or narrower in the same was as notepad would with word wrap on. Is there anything in the Windows API that has already solved this problem?
-
I need to split a paragraph into lines based on a given width in pixels. The idea being that as a user resizes the window, they can see more or less of the paragraph as the window is made wider or narrower in the same was as notepad would with word wrap on. Is there anything in the Windows API that has already solved this problem?
Depends on the context. What are you doing exactly? If you're drawing the string yourself, the Graphics method DrawString already does this for you. You just have to provide the rectangle to fit the string in.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
Depends on the context. What are you doing exactly? If you're drawing the string yourself, the Graphics method DrawString already does this for you. You just have to provide the rectangle to fit the string in.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave KreskowiakThanks for the suggestion but I'm looking to determine the starting offset of each line within the paragraph. I could manually parse the string and use GetTextExtentPoint32() to work it out myself but I imagine that will be slow and I thought maybe an API might already exist as something like an edit control will already be doing something similar.
AxisFirst For Business
-
Thanks for the suggestion but I'm looking to determine the starting offset of each line within the paragraph. I could manually parse the string and use GetTextExtentPoint32() to work it out myself but I imagine that will be slow and I thought maybe an API might already exist as something like an edit control will already be doing something similar.
AxisFirst For Business
Ah, OK. I think you're looking for Graphics.MeasureCharacterRanges[^].
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
I need to split a paragraph into lines based on a given width in pixels. The idea being that as a user resizes the window, they can see more or less of the paragraph as the window is made wider or narrower in the same was as notepad would with word wrap on. Is there anything in the Windows API that has already solved this problem?
-
Probably easier to use an Edit Control | Microsoft Docs[^].
+100 to that answer .. Multiline edit boxes already exist why re-invent the wheel.
In vino veritas
-
+100 to that answer .. Multiline edit boxes already exist why re-invent the wheel.
In vino veritas
-
I need to split a paragraph into lines based on a given width in pixels. The idea being that as a user resizes the window, they can see more or less of the paragraph as the window is made wider or narrower in the same was as notepad would with word wrap on. Is there anything in the Windows API that has already solved this problem?
Look at ExtTextOut.