Drawstring question...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • johnb41

    #1

    Drawstring question...

    I need to print out a string of text and obviously i'm using the
    DrawString command.

    But the string must be placed AFTER some "programmatical ly generated
    text" (also printed using DrawString). That text would range from a
    single line, to maybe up to 10 lines. So i cannot hard code the
    position for the Drawstring command... it must come AFTER the generated
    text, where ever that might be.

    Is there any way to determine the position (x,y) of the end of the auto
    generated text? I could then take that value and then add a little bit
    to it.

    I'm totally stumped with this and would appreciate some help or
    direction.

    Thanks,
    John

  • Mythran

    #2
    Re: Drawstring question...


    "johnb41" <jsbuchmann@gma il.comwrote in message
    news:1155144202 .591285.306250@ i3g2000cwc.goog legroups.com...
    >I need to print out a string of text and obviously i'm using the
    DrawString command.
    >
    But the string must be placed AFTER some "programmatical ly generated
    text" (also printed using DrawString). That text would range from a
    single line, to maybe up to 10 lines. So i cannot hard code the
    position for the Drawstring command... it must come AFTER the generated
    text, where ever that might be.
    >
    Is there any way to determine the position (x,y) of the end of the auto
    generated text? I could then take that value and then add a little bit
    to it.
    >
    I'm totally stumped with this and would appreciate some help or
    direction.
    >
    Thanks,
    John
    >
    Use the MeasureString method of the Graphics object to obtain the rectangle
    that contains the size of the text. Add this to the x and y positions you
    passed to the DrawString of the original text and voila, the ending x and y
    positions you want :)

    HTH,
    Mythran


    Comment

    • johnb41

      #3
      Re: Drawstring question...

      Thanks! I got it to work. The MeasureString method actually returns a
      PointF, not a rectangle. But from that i can get the "height" which is
      what i need. :)

      John

      Use the MeasureString method of the Graphics object to obtain the rectangle
      that contains the size of the text. Add this to the x and y positions you
      passed to the DrawString of the original text and voila, the ending x and y
      positions you want :)
      >
      HTH,
      Mythran

      Comment

      • Mythran

        #4
        Re: Drawstring question...


        "johnb41" <jsbuchmann@gma il.comwrote in message
        news:1155152387 .349414.136530@ 75g2000cwc.goog legroups.com...
        Thanks! I got it to work. The MeasureString method actually returns a
        PointF, not a rectangle. But from that i can get the "height" which is
        what i need. :)
        >
        John
        >
        >
        >Use the MeasureString method of the Graphics object to obtain the
        >rectangle
        >that contains the size of the text. Add this to the x and y positions
        >you
        >passed to the DrawString of the original text and voila, the ending x and
        >y
        >positions you want :)
        >>
        >HTH,
        >Mythran
        >
        Hmm, .Net 2005 ... MeasureString returns a PointF? PointF contains Height?
        Hmm, I thought a PointF was a floating point version of a Point structure
        which contains 2 members, X and Y (hence, Point...since a single point in
        space has no physical dimensions, just a location [x and y]).

        Mythran


        Comment

        • johnb41

          #5
          Re: Drawstring question...

          Oops, my bad! It returns a SizeF, which from that you can get the
          width and height properties. Not PointF, sorry!

          John

          Hmm, .Net 2005 ... MeasureString returns a PointF? PointF contains Height?
          Hmm, I thought a PointF was a floating point version of a Point structure
          which contains 2 members, X and Y (hence, Point...since a single point in
          space has no physical dimensions, just a location [x and y]).
          >
          Mythran

          Comment

          • Mythran

            #6
            Re: Drawstring question...


            "johnb41" <jsbuchmann@gma il.comwrote in message
            news:1155218380 .162897.48490@p 79g2000cwp.goog legroups.com...
            Oops, my bad! It returns a SizeF, which from that you can get the
            width and height properties. Not PointF, sorry!
            >
            John
            >
            >
            >Hmm, .Net 2005 ... MeasureString returns a PointF? PointF contains
            >Height?
            >Hmm, I thought a PointF was a floating point version of a Point structure
            >which contains 2 members, X and Y (hence, Point...since a single point in
            >space has no physical dimensions, just a location [x and y]).
            >>
            >Mythran
            >
            Aye, makes sense :) I could have checked it out myself and would probably
            wouldn't have needed this discussion. The funny thing is, I was using
            MeasureString extensively the other day, and it slipped my mind lol

            Glad it works for ya :)

            Mythran


            Comment

            Working...