DrawString, multiline string but full width

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sin Jeong-hun

    DrawString, multiline string but full width

    Hello.
    It seems like the default behavior of DrawString is trying to keep the
    whole word if possible. I'd like the string to be drawn in multilines,
    but filling the entire line width.
    For example I'm using a fixed-width font, and the width of the layout
    rectangle is that of 12 characters, the result I want is,
    This is a sa
    mple text.
    not,
    This is a
    sample text.

    I set the StringFormatFla gs.Wrap = false, but it disabled multiline
    drawing that wasn't what I wanted.

    Is what I'm trying to do achievable with any formatting options or do
    I have to draw each character manually with my own calculation?
  • Peter Duniho

    #2
    Re: DrawString, multiline string but full width

    On Fri, 25 Apr 2008 21:51:04 -0700, Sin Jeong-hun <typingcat@gmai l.com>
    wrote:
    It seems like the default behavior of DrawString is trying to keep the
    whole word if possible. I'd like the string to be drawn in multilines,
    but filling the entire line width.
    [...]
    Is what I'm trying to do achievable with any formatting options or do
    I have to draw each character manually with my own calculation?
    Off the top of my head, I think maybe you want to set the
    StringFormat.Tr imming property to Character.

    If I'm mistaken about that, you may be able to use the TextRenderer class
    instead to do your drawing, using the TextFormatFlags .WordBreak flag (or
    rather, making sure that flag is _not_ set) to have the text wrapped on
    whatever character reaches the very end of the line.

    Sorry I'm being so vague...I don't have something right in front of me
    that would let me test the code to make sure my recollection is right.

    Pete

    Comment

    • Sin Jeong-hun

      #3
      Re: DrawString, multiline string but full width

      On Apr 26, 3:29 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
      wrote:
      On Fri, 25 Apr 2008 21:51:04 -0700, Sin Jeong-hun <typing...@gmai l.com 
      wrote:
      >
      It seems like the default behavior of DrawString is trying to keep the
      whole word if possible. I'd like the string to be drawn in multilines,
      but filling the entire line width.
      [...]
      Is what I'm trying to do achievable with any formatting options or do
      I have to draw each character manually with my own calculation?
      >
      Off the top of my head, I think maybe you want to set the  
      StringFormat.Tr imming property to Character.
      >
      If I'm mistaken about that, you may be able to use the TextRenderer class  
      instead to do your drawing, using the TextFormatFlags .WordBreak flag (or  
      rather, making sure that flag is _not_ set) to have the text wrapped on  
      whatever character reaches the very end of the line.
      >
      Sorry I'm being so vague...I don't have something right in front of me  
      that would let me test the code to make sure my recollection is right.
      >
      Pete
      Thank you for your reply. But, DrawString() with Trimming property set
      to Character didn't work. It was the same as when I didn't even set
      the Trimming property. Secondly, TextRender.Draw Text draws multiline
      text if and only if the TextFormatFlag has WordBreak. Setting
      WorkBreak gave the same result as when I used DrawString().

      Comment

      • Sin Jeong-hun

        #4
        Re: DrawString, multiline string but full width

        On Apr 26, 5:27 pm, Sin Jeong-hun <typing...@gmai l.comwrote:
        On Apr 26, 3:29 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
        wrote:
        >
        >
        >
        On Fri, 25 Apr 2008 21:51:04 -0700, Sin Jeong-hun <typing...@gmai l.com 
        wrote:
        >
        It seems like the default behavior of DrawString is trying to keep the
        whole word if possible. I'd like the string to be drawn in multilines,
        but filling the entire line width.
        [...]
        Is what I'm trying to do achievable with any formatting options or do
        I have to draw each character manually with my own calculation?
        >
        Off the top of my head, I think maybe you want to set the  
        StringFormat.Tr imming property to Character.
        >
        If I'm mistaken about that, you may be able to use the TextRenderer class  
        instead to do your drawing, using the TextFormatFlags .WordBreak flag (or 
        rather, making sure that flag is _not_ set) to have the text wrapped on  
        whatever character reaches the very end of the line.
        >
        Sorry I'm being so vague...I don't have something right in front of me  
        that would let me test the code to make sure my recollection is right.
        >
        Pete
        >
        Thank you for your reply. But, DrawString() with Trimming property set
        to Character didn't work. It was the same as when I didn't even set
        the Trimming property. Secondly, TextRender.Draw Text draws multiline
        text if and only if the TextFormatFlag has WordBreak. Setting
        WorkBreak gave the same result as when I used DrawString().
        Please just let me know if what I'm trying to do cannot be achieved
        with some flags. Then I can start writing manual line breaking codes.
        Thank you.

        Comment

        • Peter Duniho

          #5
          Re: DrawString, multiline string but full width

          On Sat, 26 Apr 2008 18:29:12 -0700, Sin Jeong-hun <typingcat@gmai l.com>
          wrote:
          Please just let me know if what I'm trying to do cannot be achieved
          with some flags. Then I can start writing manual line breaking codes.
          For what it's worth, it's very difficult with many esoteric operations for
          a person to say for sure that you can't do it easily in .NET. .NET is
          incredibly broad in many areas. If a person knows for sure that there
          _is_ a way to do it, that's one thing. But to prove that you can't is
          much harder.

          In other words, you may not find anyone who is confident that their
          knowledge is encyclopedic enough about .NET to state for sure that there's
          no option that will break a line within a word rather than between words.
          And this may be true even if it turns out that you actually can't.

          I'm actually surprised that neither of the options I mentioned address the
          issue. Just as I can't say for sure that what you want isn't in .NET, I
          also can't say for sure that you have successfully applied the options I
          mentioned in a way that would perform as you want. It's possible that
          they only work in that specific way when used in combination with other
          aspects of text formatting and that you haven't tried that particular
          combination yet.

          But, the fact is that Graphics.DrawSt ring() and TextRenderer.Dr awText()
          are the two primary ways to draw text in .NET. If you're sure you've
          explored all of the viable combinations of settings and overloads for each
          of those methods and none do what you want, I suppose you might as well
          start working on a more explicit implementation instead.

          Pete

          Comment

          Working...