Currently trying to print an ultragrid, it has several columns and I found the FitWidthToPage method under initialize print preview. I'm trying to find out if there is a way to minimize the margins on the left and right on print preview and when it prints so that the page will have more room to fit the columns. I haven't been able to find any answers yet so I figured I would try the forums. Does anyone have any experience with this kind of situation or know if it is possible to get rid of margins for the print preview and when printing?
Hi,
You can set the margins on the PrintDocument.DefaultPageSettings. But every printer has a minimum margin on which the printer will not print. So to reduce the margins to the minimum, you could do something like this:
private void ultraGrid1_InitializePrintPreview(object sender, CancelablePrintPreviewEventArgs e) { e.PrintDocument.DefaultPageSettings.Margins.Left = (int)Math.Ceiling(e.PrintDocument.DefaultPageSettings.HardMarginX); e.PrintDocument.DefaultPageSettings.Margins.Right = (int)Math.Ceiling(e.PrintDocument.DefaultPageSettings.HardMarginX); e.DefaultLogicalPageLayoutInfo.FitWidthToPages = 1; }
I'm not sure I understand what you mean about the grid being too small. That seems to be contradictory to your first post. You want to decrease the margins to make more space but at the same time the grid is too small? That doesn't make sense. I suspect I am just misunderstanding what you mean.
Hey Mike,
Thanks for the response. That did the trick. If you can answer one more question for me: we're using an Ultragrid.PrintPreview() right now to print the data from the grid. Is there a way to put a title and/or time stamp on this when they print it?
You could use the e.DefaultLogicalPageLayoutInfo.PageHeader and/or PageFooter for that.