C# Printing Problem

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

    #1

    C# Printing Problem

    I am having a problem printing in C#. I am using DrawString() with
    the RectagleF class to determine the location to print. I am doing it
    this way so that I can get the text to auto wrap.

    The problem I am having is this: Is there any way to make the
    rectangle grow based on the contents or a way to determine exactly
    what the height should be so I do not lose text when printing? The
    data I am printing will contain line breaks so I cannot use a fuction
    that will simply tell me how long the string is based on the font
    size.

    Any ideas anyone?

    Dane
  • A

    #2
    Re: C# Printing Problem

    > The problem I am having is this: Is there any way to make the[color=blue]
    > rectangle grow based on the contents or a way to determine exactly
    > what the height should be so I do not lose text when printing? The
    > data I am printing will contain line breaks so I cannot use a fuction
    > that will simply tell me how long the string is based on the font
    > size.[/color]

    If you know the maximum width of the area you wish to print in, then you can
    use the Graphics.Measur eString function because that can take in an optional
    max width. If you do not know the max width, then One can only assume that
    it's actually 1 line per line break, in which you can simply read the number
    of line breaks and then you will know how many lines you have, and can
    measure the height appropriately by measuring one line and multiplying by
    the total number of lines.

    -akshay


    Comment

    • Ron Allen

      #3
      Re: C# Printing Problem

      Dane,
      Use the overload of MeasureString that returns the #of lines fitted to a
      SizeF area and make the SizeF for this the correct width and tall enough to
      avoid overflow. You will get back the # of lines fitted. This overload
      returns both # of characters and # of lines fitted.

      Ron Allen
      "Dane" <dane@dtmtechno logies.net> wrote in message
      news:4b4320ea.0 307161240.cf2d8 a0@posting.goog le.com...[color=blue]
      > I am having a problem printing in C#. I am using DrawString() with
      > the RectagleF class to determine the location to print. I am doing it
      > this way so that I can get the text to auto wrap.
      >
      > The problem I am having is this: Is there any way to make the
      > rectangle grow based on the contents or a way to determine exactly
      > what the height should be so I do not lose text when printing? The
      > data I am printing will contain line breaks so I cannot use a fuction
      > that will simply tell me how long the string is based on the font
      > size.
      >
      > Any ideas anyone?
      >
      > Dane[/color]


      Comment

      Working...