Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Wrapped String Calculation

Wrapped String Calculation

Scheduled Pinned Locked Moved C#
tutorialquestiongraphicshelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    azusakt
    wrote on last edited by
    #1

    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?

    C A 2 Replies Last reply
    0
    • A azusakt

      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?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • A azusakt

        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?

        A Offline
        A Offline
        azusakt
        wrote on last edited by
        #3

        Could anyone show me some examples? I feeling difficult how to initial the Graphics, so that it measure the String in correct unit,

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups