Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2005

Tip: Looking for answers? Try searching our database.

PrintPage and table format

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Siu - 09 Feb 2005 14:35 GMT
Hi,
does anybody have an example of PrintPage event which builds a PrintDocument
as a table and handles also the size of columns contents like this:

Title1               |Title2                 |Title3
================================
first cell has     |second cell          |also third
a text longer    |                         |cell has a longer
than the size    |                         | text
column            |                         |
-----------------------------------------------------------
new line and    |new line,second  |new line third cell
new cell          | cell                    |  
-----------------------------------------------------------

So far, I've built only the table, but I can't handle the content according to
the column size.

PLEASE HELP ME..... ;)
Ron Allen - 09 Feb 2005 14:52 GMT
Siu,
   I haven't done this directly as a table but I have handled wrapping text
within a boundary to multiple lines. Use the Graphics.DrawString overload
that returns the number of lines used i.e.
   Graphics.DrawString("draw this", aFont, aRectangleF,
StringFormat.GenericTypographic)
to draw the string and
   MeasureString("draw this", aFont, aSizeF,
StringFormat.GenericTypographic, nChars, nLines) where nChars and nLines are
out variables and aSizeF is a SizeF the width and height of the RectangleF
used to draw the string.  Make aRectangleF as wide as you need to draw in
and high enough to take several lines of text.  Its' left x and top y values
are where the drawing will start.
   Using these for each cell you can get the maximum height in lines of the
cells in a row and use this to advance the y location as required.  The
DrawString will wrap at word breaks and truncate the text when it runs out
of space in the specified rectangle.  You can check nChars to see how many
characters fit in the specified rectangle and do a page advance if not
enough fit.  Of course if you do this you will have to do all the
MeasureString calls for a line first.

Ron Allen
> Hi,
> does anybody have an example of PrintPage event which builds a
[quoted text clipped - 17 lines]
>
> PLEASE HELP ME..... ;)
Siu - 09 Feb 2005 15:11 GMT
Hi Ron,
can you please send to me your code? It's difficult to me understanding what
you have written...

Thank you ;)

> Siu,
>     I haven't done this directly as a table but I have handled wrapping text
[quoted text clipped - 39 lines]
> >
> > PLEASE HELP ME..... ;)
Ron Allen - 10 Feb 2005 20:24 GMT
Siu,
   I have this encapsulated in a routine that may be somewhat opaque but
here it is.  Note that all my drawing routines take measurements in inches
and assume that the default (1/100th inch) measurement unit is used for the
Graphics.  The following draws the string supplied in a rectangle with the
specified left, right, top, bottom coordinates using the specified brush and
font.
   I can't really send the code that calls this out-of-house.

Ron Allen

 public int PrintInRect(Graphics g, Brush b, Font f, float x, float y,
float xr, float yb, String s, StringFormat sFmt)
 {
   // arguments are supplied in inches and the default measurement is used
  // places the left edge of the string at the supplied x location
  // assume user has done a translatetransform on the graphics for the hard
margins
   // x is the right hand edge of the rectangle to print in, xr is the
lefthand edge
   // y is the top edge and yb is the bottom edge
  float x1 = (100.0f * x); // convert to 100ths of inches
  float y1 = (100.0f * y);
  float x1r = (100.0f * xr);
  float y1b = (100.0f * yb);
   // make sure that these are all positive or zero
  x1 = Math.Max(x1, 0.0f);
  y1 = Math.Max(y1, 0.0f);
  x1r = Math.Max(x1r, 0.0f);
  y1b = Math.Max(y1b, 0.0f);
  int nLines, nChars;
   // create the RectangleF to draw in
  RectangleF rect = new RectangleF(x1, y1, (x1r - x1), (y1b - y1));
   // and the SizeF for measuring
  SizeF sz = new SizeF((x1r - x1), (y1b - y1));
   // measure lines and characters used.  Note nChars is presently
disregarded.
  g.MeasureString(s, f, sz, sFmt, out nChars, out nLines);
   // draw in the desired rectangle with wrapping
  g.DrawString(s, f, b, rect, sFmt);
  return nLines;    // get back the # of lines that this used
 }

> Hi Ron,
> can you please send to me your code? It's difficult to me understanding
[quoted text clipped - 32 lines]
>>
>> Ron Allen

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.