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. Space width.

Space width.

Scheduled Pinned Locked Moved C#
question
10 Posts 4 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.
  • K Offline
    K Offline
    KBou
    wrote on last edited by
    #1

    I've got a TextBlock wich varies in With and FontSize. I want to fill it completely with spaces. How can I calculate how much spaces I need to fill the entire TextBlock? gr. Kevin

    D 1 Reply Last reply
    0
    • K KBou

      I've got a TextBlock wich varies in With and FontSize. I want to fill it completely with spaces. How can I calculate how much spaces I need to fill the entire TextBlock? gr. Kevin

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      Do you want to replace all text with spaces? Just get the text length and insert as many spaces.

      Avoid Google. Use Blackle[^]

      K 1 Reply Last reply
      0
      • D dan sh

        Do you want to replace all text with spaces? Just get the text length and insert as many spaces.

        Avoid Google. Use Blackle[^]

        K Offline
        K Offline
        KBou
        wrote on last edited by
        #3

        "Do you want to replace all text with spaces?" No. The situation is a bit more complex. But lets say the TextBlock is empty and I would want to fill it with spaces. The only data I have is the Width of the TextBlock and the FontSize. If I would know the "width" of a space in the same FontSize I could calculate how many I would need. But how do I calculate the width of a space?

        D 1 Reply Last reply
        0
        • K KBou

          "Do you want to replace all text with spaces?" No. The situation is a bit more complex. But lets say the TextBlock is empty and I would want to fill it with spaces. The only data I have is the Width of the TextBlock and the FontSize. If I would know the "width" of a space in the same FontSize I could calculate how many I would need. But how do I calculate the width of a space?

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          Graphics.MeasureString can give you size of string in mentioned font. Will that help?

          Avoid Google. Use Blackle[^]

          K 1 Reply Last reply
          0
          • D dan sh

            Graphics.MeasureString can give you size of string in mentioned font. Will that help?

            Avoid Google. Use Blackle[^]

            K Offline
            K Offline
            KBou
            wrote on last edited by
            #5

            I sounds like it could work. But how do I use it? I can't make a new instance of it, like Graphics g = new Graphics();, And when I just use Graphics. I don't get MeasureString. Can you help me with this.

            D B 2 Replies Last reply
            0
            • K KBou

              I sounds like it could work. But how do I use it? I can't make a new instance of it, like Graphics g = new Graphics();, And when I just use Graphics. I don't get MeasureString. Can you help me with this.

              D Offline
              D Offline
              dan sh
              wrote on last edited by
              #6

              Graphics oGx = this.CreateGraphics(); I still dont understand the requirement to insert spaces.

              Avoid Google. Use Blackle[^]

              K 1 Reply Last reply
              0
              • D dan sh

                Graphics oGx = this.CreateGraphics(); I still dont understand the requirement to insert spaces.

                Avoid Google. Use Blackle[^]

                K Offline
                K Offline
                KBou
                wrote on last edited by
                #7

                Maybe I should have mentioned that I'm creating WPF application and not a WindowsForms application. I have a TextBlock in a ScrollViewer. The ScrollViewer moves it position so you will see another part of the TextBlock. This creates somekind of Marque. At the start I want the text to start off the screen therefor I need the spaces.

                P 1 Reply Last reply
                0
                • K KBou

                  I sounds like it could work. But how do I use it? I can't make a new instance of it, like Graphics g = new Graphics();, And when I just use Graphics. I don't get MeasureString. Can you help me with this.

                  B Offline
                  B Offline
                  benjymous
                  wrote on last edited by
                  #8

                  You need to use the Graphics context that you're currently rendering with (e.g. the one that's passed in to the OnPaint method)

                  -- Help me! I'm turning into a grapefruit! Buzzwords!

                  1 Reply Last reply
                  0
                  • K KBou

                    Maybe I should have mentioned that I'm creating WPF application and not a WindowsForms application. I have a TextBlock in a ScrollViewer. The ScrollViewer moves it position so you will see another part of the TextBlock. This creates somekind of Marque. At the start I want the text to start off the screen therefor I need the spaces.

                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #9

                    You should have: a) Posted this on the WPF forum and b) looked into the FormattedText class to see what methods are available there (hint - take a look at the GetMaxWidths method).

                    Deja View - the feeling that you've seen this post before.

                    My blog | My articles

                    K 1 Reply Last reply
                    0
                    • P Pete OHanlon

                      You should have: a) Posted this on the WPF forum and b) looked into the FormattedText class to see what methods are available there (hint - take a look at the GetMaxWidths method).

                      Deja View - the feeling that you've seen this post before.

                      My blog | My articles

                      K Offline
                      K Offline
                      KBou
                      wrote on last edited by
                      #10

                      Thanks. I'll post these thing in the WPF forum the next time. For the Info: I've used the formattedText.WidthIncludingTrailingWhitespace Methode to calculate the width of 1 space.

                      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