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. Text formatting

Text formatting

Scheduled Pinned Locked Moved C#
graphicshelpquestion
6 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.
  • S Offline
    S Offline
    Skymir
    wrote on last edited by
    #1

    I'm trying to add spacing to the beginning of some text so that I can put small symbols before specific lines of text. The size of the symbols is always the same, 10x10 pixels, however the number of symbols can range from none to half a dozen. The problem I'm running in to is figuring out the number of spaces to indent the text. Normally I'd simply move the bounding box over by the size of the bullets, but in this case, the next line of text needs to wrap under the graphics I'm inserting, so moving the bounding box cuts down on the space available for text. Right now I'm just adding in 3 * the number of spaces as there are symbols in hopes of getting close, but it's a bit off. I've tried using MeasureString to get the size of a space, then adding enough spaces to move the text, but it comes out too little with only 1 symbol and not nearly enough by the time there are 4 or more symbols. Any suggestions?

    The true man wants two things: danger and play. For that reason he wants woman, as the most dangerous plaything.

    OriginalGriffO 1 Reply Last reply
    0
    • S Skymir

      I'm trying to add spacing to the beginning of some text so that I can put small symbols before specific lines of text. The size of the symbols is always the same, 10x10 pixels, however the number of symbols can range from none to half a dozen. The problem I'm running in to is figuring out the number of spaces to indent the text. Normally I'd simply move the bounding box over by the size of the bullets, but in this case, the next line of text needs to wrap under the graphics I'm inserting, so moving the bounding box cuts down on the space available for text. Right now I'm just adding in 3 * the number of spaces as there are symbols in hopes of getting close, but it's a bit off. I've tried using MeasureString to get the size of a space, then adding enough spaces to move the text, but it comes out too little with only 1 symbol and not nearly enough by the time there are 4 or more symbols. Any suggestions?

      The true man wants two things: danger and play. For that reason he wants woman, as the most dangerous plaything.

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Why not always start the text with a symbol? Use a blank one instead of your spaces and off you go. I don't think spaces are a good way to go; the width of a space can vary depending on the font - start a reply to this and compare the width of a space in the "Subject" and "Text" areas. The font size is the same, but the space width is different.

      No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      S 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Why not always start the text with a symbol? Use a blank one instead of your spaces and off you go. I don't think spaces are a good way to go; the width of a space can vary depending on the font - start a reply to this and compare the width of a space in the "Subject" and "Text" areas. The font size is the same, but the space width is different.

        No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

        S Offline
        S Offline
        Skymir
        wrote on last edited by
        #3

        That's why I was using measurestring to check the size of the space in whatever font was being used at that moment. As for always using a symbol, that would be simple, except the number of symbols changes. What would be nice is if there were a way to indent text within a bounding box, by a set number of pixels. Just like in a text editor where if you go to the beginning of a paragraph and insert tab, everything indents and the word wrap updates to fit each following line. The only other thing I've thought of so far would be doing the word wrap manually by measuring each line and breaking up the string until it fit. I've just hoped to avoid that since it's going to involve rounding between lines, making the line spacing squirrely.

        The true man wants two things: danger and play. For that reason he wants woman, as the most dangerous plaything.

        OriginalGriffO 1 Reply Last reply
        0
        • S Skymir

          That's why I was using measurestring to check the size of the space in whatever font was being used at that moment. As for always using a symbol, that would be simple, except the number of symbols changes. What would be nice is if there were a way to indent text within a bounding box, by a set number of pixels. Just like in a text editor where if you go to the beginning of a paragraph and insert tab, everything indents and the word wrap updates to fit each following line. The only other thing I've thought of so far would be doing the word wrap manually by measuring each line and breaking up the string until it fit. I've just hoped to avoid that since it's going to involve rounding between lines, making the line spacing squirrely.

          The true man wants two things: danger and play. For that reason he wants woman, as the most dangerous plaything.

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          But if your symbols are always the same size (as you said) just use the appropriate number of blank symbols. You cannot guarentee to get the same size with spaces - there may not be a neat multiple to ten, twenty and so on pixels. Avoid manual word wrap - I had to do it yonks ago (pre windows) and it is a PITA.

          No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          S 2 Replies Last reply
          0
          • OriginalGriffO OriginalGriff

            But if your symbols are always the same size (as you said) just use the appropriate number of blank symbols. You cannot guarentee to get the same size with spaces - there may not be a neat multiple to ten, twenty and so on pixels. Avoid manual word wrap - I had to do it yonks ago (pre windows) and it is a PITA.

            No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

            S Offline
            S Offline
            Skymir
            wrote on last edited by
            #5

            Each Symbol is the same size, however if there's only 1 symbol and I leave room for 6 of them, then I've lost half of that line of text. The print out is about 2.25" x 2.25" a little smaller than half a playing card. So each bit of space is a premium.

            The true man wants two things: danger and play. For that reason he wants woman, as the most dangerous plaything.

            1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              But if your symbols are always the same size (as you said) just use the appropriate number of blank symbols. You cannot guarentee to get the same size with spaces - there may not be a neat multiple to ten, twenty and so on pixels. Avoid manual word wrap - I had to do it yonks ago (pre windows) and it is a PITA.

              No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

              S Offline
              S Offline
              Skymir
              wrote on last edited by
              #6

              Sadly, doing my own word wrap ended up being the solution. For now it's only the first line, I'm going to end up having to do the rest of it though. There are going to end up being symbols in the middle of the text later on. The bugger I'm just realizing is that I can't even cheat and make my own font since the text around the symbols would be in a different (varying size) font, requiring separate calls to Drawstring. On the bright side, the output is a printed label, so at least I don't have to worry about keeping up a frame rate.

              The true man wants two things: danger and play. For that reason he wants woman, as the most dangerous plaything.

              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