Wrapped String Calculation
-
Hi, I'm thinking how to do a text wrap calculation for a string by myself. I need to calculate how many lines will a string wrapped to (within a fixed area region). The fixed region is a location and an area for filling the string. I also have to know which part of the string is wrapped to the corresponding line. Could some of you give me some ideas? e.g. string txt1 = "AbcdefgHigklmnopqrstuvWxyz. Dear, Hello Hello My Friend..."; if the fill region is limited to the size of "100x400", what is the good way to calculate how many lines will the txt1 wrapped to? as we can imagine, txt1 maybe wrapped into 3 lines. 1st line: AbcdefgHigklmnopqrs 2nd line: tuvWxyz. Dear, Hello 3rd line: Hello My Friend... I'm thinking to use graphics.MeasureString to calculate the width of each character. is it a good way.. I would be appreciated if you can give me some example? Thanks so much for your help?
-
Hi, I'm thinking how to do a text wrap calculation for a string by myself. I need to calculate how many lines will a string wrapped to (within a fixed area region). The fixed region is a location and an area for filling the string. I also have to know which part of the string is wrapped to the corresponding line. Could some of you give me some ideas? e.g. string txt1 = "AbcdefgHigklmnopqrstuvWxyz. Dear, Hello Hello My Friend..."; if the fill region is limited to the size of "100x400", what is the good way to calculate how many lines will the txt1 wrapped to? as we can imagine, txt1 maybe wrapped into 3 lines. 1st line: AbcdefgHigklmnopqrs 2nd line: tuvWxyz. Dear, Hello 3rd line: Hello My Friend... I'm thinking to use graphics.MeasureString to calculate the width of each character. is it a good way.. I would be appreciated if you can give me some example? Thanks so much for your help?
MeasureString can be used on the whole string, keep cutting until it fits. Make a string of what's left and start again.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Hi, I'm thinking how to do a text wrap calculation for a string by myself. I need to calculate how many lines will a string wrapped to (within a fixed area region). The fixed region is a location and an area for filling the string. I also have to know which part of the string is wrapped to the corresponding line. Could some of you give me some ideas? e.g. string txt1 = "AbcdefgHigklmnopqrstuvWxyz. Dear, Hello Hello My Friend..."; if the fill region is limited to the size of "100x400", what is the good way to calculate how many lines will the txt1 wrapped to? as we can imagine, txt1 maybe wrapped into 3 lines. 1st line: AbcdefgHigklmnopqrs 2nd line: tuvWxyz. Dear, Hello 3rd line: Hello My Friend... I'm thinking to use graphics.MeasureString to calculate the width of each character. is it a good way.. I would be appreciated if you can give me some example? Thanks so much for your help?