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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. glitches in my generic printengine class!

glitches in my generic printengine class!

Scheduled Pinned Locked Moved C#
comgraphicsdesignquestion
4 Posts 2 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.
  • G Offline
    G Offline
    giddy_guitarist
    wrote on last edited by
    #1

    hi , After reading a few articles , i made this printEngine class that derives from PrintDocument. The print engine takes any class that exposes the IPrintableDocument interface. This interface defines a method that supplies a PrintablePage to the exposing class which should fill the page with classes that expose IPrintableSection. Its not very complicated but it does have a few flaws. Like although it _can_ handle pagination , it does'nt do it very well. The class that exposes IPrintableDocument has to return true/false depending on whether it need to add another page! Also , the TableRowSection does'nt work very well. Obviously , i have to make a whole table class because there needs to be column sizes added. The TableRowSection draws cells according to its own cell text sizes. To make a whole Table class i need to have the graphics class to calculate the sizes of largest text and the whole table. Should i have the PrintablePage send a graphics to the Table class? Also Could someone please check the code and tell me if the design is ok? I should mention that i'm a self taught newbie! Heres the code: http://gidsfiles.googlepages.com/PrintingCore.cs http://gidsfiles.googlepages.com/PrintableSections.cs http://gidsfiles.googlepages.com/PrintTest.cs This is how the print engine is used with the printTest class: PrintEngine pDoc = new PrintEngine(); pDoc.PrintableDocument = new PrintTest(); PrintDialog prt = new PrintDialog(); prt.Document = pDoc; prt.ShowDialog(); PrintPreviewDialog prev = new PrintPreviewDialog(); prev.Document = pDoc; prev.ShowDialog(); Thanks so much Gideon

    R 1 Reply Last reply
    0
    • G giddy_guitarist

      hi , After reading a few articles , i made this printEngine class that derives from PrintDocument. The print engine takes any class that exposes the IPrintableDocument interface. This interface defines a method that supplies a PrintablePage to the exposing class which should fill the page with classes that expose IPrintableSection. Its not very complicated but it does have a few flaws. Like although it _can_ handle pagination , it does'nt do it very well. The class that exposes IPrintableDocument has to return true/false depending on whether it need to add another page! Also , the TableRowSection does'nt work very well. Obviously , i have to make a whole table class because there needs to be column sizes added. The TableRowSection draws cells according to its own cell text sizes. To make a whole Table class i need to have the graphics class to calculate the sizes of largest text and the whole table. Should i have the PrintablePage send a graphics to the Table class? Also Could someone please check the code and tell me if the design is ok? I should mention that i'm a self taught newbie! Heres the code: http://gidsfiles.googlepages.com/PrintingCore.cs http://gidsfiles.googlepages.com/PrintableSections.cs http://gidsfiles.googlepages.com/PrintTest.cs This is how the print engine is used with the printTest class: PrintEngine pDoc = new PrintEngine(); pDoc.PrintableDocument = new PrintTest(); PrintDialog prt = new PrintDialog(); prt.Document = pDoc; prt.ShowDialog(); PrintPreviewDialog prev = new PrintPreviewDialog(); prev.Document = pDoc; prev.ShowDialog(); Thanks so much Gideon

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      Hi, Hard to say what to change without having more detailed requirements. It would be interesting to know if you need to print one large table spread over several tables. First of all you will by sure need one PrintableSection for a whole table. Like you already noticed you will need this to calculate proper widths for all the table entries. I also think this makes it easier and provides better variability than trying to make one section for each row. Surely ot needs the Graphics to determine its size, but you already have the GetSize function which should be sufficient also for the TableSection. Personally I would change the IPrintableDocument.SetPage call to something like PrintablePage[] GetPages(Graphics g, Rectangle pageBounds). This way IPrintableDocument implementations can straight away return any number of pages with its own page break logic. As you already have a return value in the AddSection function the IPrintableDocument would even have an easy hint when it needs to create a new page. With the array of pages your PrintEngine could than easily print page by page until done. Robert

      G 1 Reply Last reply
      0
      • R Robert Rohde

        Hi, Hard to say what to change without having more detailed requirements. It would be interesting to know if you need to print one large table spread over several tables. First of all you will by sure need one PrintableSection for a whole table. Like you already noticed you will need this to calculate proper widths for all the table entries. I also think this makes it easier and provides better variability than trying to make one section for each row. Surely ot needs the Graphics to determine its size, but you already have the GetSize function which should be sufficient also for the TableSection. Personally I would change the IPrintableDocument.SetPage call to something like PrintablePage[] GetPages(Graphics g, Rectangle pageBounds). This way IPrintableDocument implementations can straight away return any number of pages with its own page break logic. As you already have a return value in the AddSection function the IPrintableDocument would even have an easy hint when it needs to create a new page. With the array of pages your PrintEngine could than easily print page by page until done. Robert

        G Offline
        G Offline
        giddy_guitarist
        wrote on last edited by
        #3

        hi, thanks so much for replying. Somehow, i did'nt get a notification when you replied , so i figured that this , like the other copies i've posted over serveral forums had'nt been. I only saw your reply today. I made a whole lot of changes in the code. I made a table class that just creates TableRow sections. Like rightly said , i need the tables , but just for the calculations. So table figures sizes and creates Rows , the Rows ghtexpose IPrintableSection so they are added into the page. I gace the page the Bounds because i thought it was more correct , since bounds would belong to the page. But , yes , it does make sense returning a number of pages. Right now , i have to loop in IPrintableDocument.Print(). There still is a problem though. The rows dont print on the right Y line. They either overlap or a consecutive rows top is just after the previous rows bottom , and this varies acco rding to the font and size. Could you please just check it one more time?? Here's the source(updated): http://gidsfiles.googlepages.com/PrintingCore.cs[^] http://gidsfiles.googlepages.com/PrintableSections.cs[^] http://gidsfiles.googlepages.com/PrintTest.cs[^] Thanks so much!! Gideon

        R 1 Reply Last reply
        0
        • G giddy_guitarist

          hi, thanks so much for replying. Somehow, i did'nt get a notification when you replied , so i figured that this , like the other copies i've posted over serveral forums had'nt been. I only saw your reply today. I made a whole lot of changes in the code. I made a table class that just creates TableRow sections. Like rightly said , i need the tables , but just for the calculations. So table figures sizes and creates Rows , the Rows ghtexpose IPrintableSection so they are added into the page. I gace the page the Bounds because i thought it was more correct , since bounds would belong to the page. But , yes , it does make sense returning a number of pages. Right now , i have to loop in IPrintableDocument.Print(). There still is a problem though. The rows dont print on the right Y line. They either overlap or a consecutive rows top is just after the previous rows bottom , and this varies acco rding to the font and size. Could you please just check it one more time?? Here's the source(updated): http://gidsfiles.googlepages.com/PrintingCore.cs[^] http://gidsfiles.googlepages.com/PrintableSections.cs[^] http://gidsfiles.googlepages.com/PrintTest.cs[^] Thanks so much!! Gideon

          R Offline
          R Offline
          Robert Rohde
          wrote on last edited by
          #4

          Hi, hard to say why your positioning isn't correct by just looking at the code. Next time you should pack a sample project which can be debugged. Only thing I noticed is that you calculate the row height for each row seperately only looking at the first cell. For me this sounds like a possible source for the error. I would determine one height which should be used by all rows and is the maximum height of all contained strings. This could be done in your table class while it calculates the column widths. Robert

          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