We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Print .vs. PrintPreview in 2.0.5.0 still an issue.

Thread ID:

Created:

Updated:

Platform:

Replies:

13282 Apr 24,2004 08:28 AM May 3,2004 09:22 AM Windows Forms 5
loading
Tags: GridControl
Rick
Asked On April 24, 2004 08:28 AM

Just installed 2.0.5.0 and all went well with the upgrade. However, I''m having problems with PrintPreview and Print showing and printing the same thing. (I still have an open issue in V1.6.1.6 with this issue.) I have a grid that fills a form. I use the standard print and print preview examples in the code with the exception that I set the page margins as follows: GridPrintDocument pd = new GridPrintDocument(this.gridDesigner, true); // If we have page settings apply them. if (m_pageSettings != null) { pd.DefaultPageSettings.Margins = m_pageSettings.Margins; } PrintPreviewDialog dlg = new PrintPreviewDialog(); dlg.Document = pd; dlg.ShowDialog(); The printer I''m using has a left hard margin of .25 inches. The PrintPreview will show correctly but the print through PrintPreview or just printing directly always add the page margin plus the hard margin so it is always offset. I''ve tried setting pd.OriginAtMargins and also creating a class that inherits from GridPrintDocument and overriding the OnPrintPage and check for screen print vs. printing to the printer and adjusting the margin in the event but still no luck. Thanks, Rick

Administrator [Syncfusion]
Replied On April 26, 2004 07:09 AM

There has been no change in the 2.0.5.0 to affect a problem such as this. Instead of trying to adjust the page margins in OnPrintPage, have you tried adjusting the margins in the DefaultPageSetting before calling the pd.Print? pd.PrinterSettings.DefaultPageSettings.Margins If you place a stop in your print routine and put the pd object in a Quick Watch window, is there something that reflects the value of your printer left hard margin? (maybe some gutter setting or something). If you could find this value, maybe you could reset it somehow???

Administrator [Syncfusion]
Replied On April 26, 2004 07:36 AM

I am having the same problem with my own PrintDocument (not GridPrintDocument). Just draw a rectangle around the margins and see the rectangle shifting. Is this a .NET issue? thanks, - Reddy

Administrator [Syncfusion]
Replied On April 27, 2004 01:11 PM

I fixed my problem looking at the following links. http://groups.google.com/groups?q=print+vs+printpreview&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=eMw6xWfHCHA.2988%40tkmsftngp12&rnum=1 http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=u5Pt8h6PCHA.2380%40tkmsftngp12&rnum=2&prev=/groups%3Fq%3Dc%2523%2Bgetdevicecaps%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3Du5Pt8h6PCHA.2380%2540tkmsftngp12%26rnum%3D2

Rick
Replied On May 3, 2004 09:16 AM

Clay, pd.PrinterSettings.DefaultPageSettings.Margins did not work but I did manage to find a solution by obtaining the hard margins for the printer. I tried hard margins before but couldn''t get it working. After looking closer at GridPrintDocument in 2.0.5.0 I finally found the solution. Here it is (hope it formats ok): Notes: 1) I''m print without the frame 2) I''ve tested clipping and it works. For example, I set the left margin to .2 but the printer has a hard margin of .25 resulting in a clipped page. Setting the left page margin to .25 printed right on the hard margin edge. 1) Create a new class derived from GridPrintDocument. (This is similar to the solutions found on the web where PrintDocument is the base class.) 2) Override OnPrintPage as follows: protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs ev) { // Original PrintPageEventArgs in the case we are doing a Print Preview. PrintPageEventArgs ppea = ev; // We need to check if this is the printer or screen. A screen will have VisibleClipBounds of X < 0 if (ev.Graphics.VisibleClipBounds.X >= 0) { // Obtain the hard margins. float left, top, right, bottom; System.IntPtr hDC = ev.Graphics.GetHdc(); DesignerTicketEditor.GetHardMargins((int)hDC, out left, out top, out right, out bottom); ev.Graphics.ReleaseHdc(hDC); // Modify the ev.MarginBounds by accounting for user requested page margins verses the hard margins. // Note: GridPrintDocument uses ev.MarginBounds so that is why we modify them. int x1 = ev.PageBounds.Left + ev.PageSettings.Margins.Left - (int)left; int y1 = ev.PageBounds.Top + ev.PageSettings.Margins.Top - (int)top; int x2 = ev.PageBounds.Right - ev.PageSettings.Margins.Right + (int)right; int y2 = ev.PageBounds.Bottom - ev.PageSettings.Margins.Bottom + (int)bottom; // We can''t override ev.MarginBounds so we create a new event with the new margin bounds. Rectangle newMargins = new Rectangle(x1, y1, x2-x1, y2-y1); ppea = new PrintPageEventArgs(ev.Graphics, newMargins, ev.PageBounds, ev.PageSettings); } base.OnPrintPage(ppea); } >There has been no change in the 2.0.5.0 to affect a problem such as this. > >Instead of trying to adjust the page margins in OnPrintPage, have you tried adjusting the margins in the DefaultPageSetting before calling the pd.Print? > >pd.PrinterSettings.DefaultPageSettings.Margins > > >If you place a stop in your print routine and put the pd object in a Quick Watch window, is there something that reflects the value of your printer left hard margin? (maybe some gutter setting or something). If you could find this value, maybe you could reset it somehow???

Rick
Replied On May 3, 2004 09:22 AM

I made a mistake. The width and height values for the new bounds are off by one unit. Rectangle newMargins = new Rectangle(x1, y1, x2-x1, y2-y1); should be Rectangle newMargins = new Rectangle(x1, y1, x2-x1+1, y2-y1+1); Rick >Clay, > >pd.PrinterSettings.DefaultPageSettings.Margins did not work but I did manage to find a solution by obtaining the hard margins for the printer. I tried hard margins before but couldn''t get it working. After looking closer at GridPrintDocument in 2.0.5.0 I finally found the solution. Here it is (hope it formats ok): > >Notes: >1) I''m print without the frame >2) I''ve tested clipping and it works. For example, I set the left margin to .2 but the printer has a hard margin of .25 resulting in a clipped page. Setting the left page margin to .25 printed right on the hard margin edge. > > >1) Create a new class derived from GridPrintDocument. (This is similar to the solutions found on the web where PrintDocument is the base class.) > >2) Override OnPrintPage as follows: > >protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs ev) >{ > // Original PrintPageEventArgs in the case we are doing a Print Preview. > PrintPageEventArgs ppea = ev; > > // We need to check if this is the printer or screen. A screen will have VisibleClipBounds of X < 0 > if (ev.Graphics.VisibleClipBounds.X >= 0) > { > // Obtain the hard margins. > float left, top, right, bottom; > System.IntPtr hDC = ev.Graphics.GetHdc(); > DesignerTicketEditor.GetHardMargins((int)hDC, out left, out top, out right, out bottom); > ev.Graphics.ReleaseHdc(hDC); > > // Modify the ev.MarginBounds by accounting for user requested page margins verses the hard margins. > // Note: GridPrintDocument uses ev.MarginBounds so that is why we modify them. > int x1 = ev.PageBounds.Left + ev.PageSettings.Margins.Left - (int)left; > int y1 = ev.PageBounds.Top + ev.PageSettings.Margins.Top - (int)top; > int x2 = ev.PageBounds.Right - ev.PageSettings.Margins.Right + (int)right; > int y2 = ev.PageBounds.Bottom - ev.PageSettings.Margins.Bottom + (int)bottom; > > // We can''t override ev.MarginBounds so we create a new event with the new margin bounds. > Rectangle newMargins = new Rectangle(x1, y1, x2-x1, y2-y1); > ppea = new PrintPageEventArgs(ev.Graphics, newMargins, ev.PageBounds, ev.PageSettings); > } > > base.OnPrintPage(ppea); >} > > > > > >>There has been no change in the 2.0.5.0 to affect a problem such as this. >> >>Instead of trying to adjust the page margins in OnPrintPage, have you tried adjusting the margins in the DefaultPageSetting before calling the pd.Print? >> >>pd.PrinterSettings.DefaultPageSettings.Margins >> >> >>If you place a stop in your print routine and put the pd object in a Quick Watch window, is there something that reflects the value of your printer left hard margin? (maybe some gutter setting or something). If you could find this value, maybe you could reset it somehow???

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;