I am working on an application that needs to print some reports that could contain some information that is displayed using the UltraGrid. A page that has a grid could contain other elemens (graphs) that show data that is usually related to the data in the grid and the paging of the report can be determined by either the content of the graph or the content of the grid (whichever has less infromation). The reports can also contain other sections that don't have a grid or have grids that contain other data.
Given these conditions, I don't think I can print the reports using the UltaGridPrintDocument and the normal printing mechanism for UltraGrid (that I used in other areas of the software). I can take care of the paging by setting the appropriate data source content for the grid. The problem is drawing the grid in the Graphics for the print or print preview. Drawing the control into a bitmap (DrawToBitmap) and then using the bitmap would print the grid, but the results are not as good as the built-in print (not to mention the fact that the printing would be slow because of the printing of a large image). I also tried to use the UI elements taht make up the grid and then call Print on those elements, but it seems there is a difference between the resolution: the elements are printed very small, even if the DPI in the Graphics is something like 600 for example).
Does anyone have other ideas or suggestions? How can someone print the grid without using UltraGridPrintDocument?
I just wanted to know if you was able to solve this issue based on Mike’s suggestions or you still need help? Just let me know. Thank you.
Sincerely,DimiDeveloper Support Engineer, MCPDInfragistics, Inc.
Unfortunately, Mike only confirmed my assumption that this is not easy to do. I implemented our own drawing of the grid during print, but it is far for being perfect. I could not find a way to get the font and alignment for each cell, I could not find a way to get the borders for the cells (e.g. some cells are merged), etc.
My biggest issue right now is that the grid seems to draw to a bitmap using a different size depending on the Graphics: when I draw to a Bitmap that was created using the display Graphics, the size is fine (matches the control’s bounds); when I draw to a Bitmap that was created using the Graphics from Print or Print Preview, the grid is taller and narrower than the bounds I set. This has an impact on the cell width, so if I draw the grid using the cell width, it ends up being narrower (I don’t care that much about the height). In the end, since I do the drawing cell by cell anyway, I expand the last column to match the area that I need to draw into. Right now I don’t have too much time to look into the DrawToBitmap problem to see if this is a bug (if someone cares about it), but I could use some help on how to get the cell properties: font, border, alignment, etc.
Actually the grid doesn't draw to a bitmap, it draws directly to the Graphics object. But the Graphics for the printer uses different units than the screen. The grid gets around this when it prints by using a Transform on the Graphics object. You could do the same thing, but it's a matter of figuring out the Transform correctly that's the tough part.
I'm talking about DrawToBitmap method of any Control, including the grid. In Print Preview for example, I set the bounds for the grid to match the area where I want the grid to be, then I create a bitmap based on the Graphics from printing and call DrawToBitmap. Somehow the drawing of the grid in the bitmap does not fill the entire bitmap (even if the bounds were set to be the same).
Anyway, is there an easy way to get the cell properties (font, border, alignment, etc.)?
How are you creating your Bitmap? If you just declare a new Bitmap, then it will be based on the screen by default. You probably need to use the overload of the Bitmap class which takes in a Graphics object and pass in the Printer's graphics so that the Bitmap itself is using the right units. Even though, the DrawToBitmap method will probably need some help converting the grid on-screen into the right units for the printer.
To answer your question, getting the font and alignment of a cell can be done using the cell's ResolveAppearance method. This wlil give you the border colors, too, but not the border style, which is determined by the override with the BorderStyleCell, BorderStyleRow, etc.