HardMarginX & HardMarginY Problems
Hi,
I'm trying to print to a HP DeskJet printer. Using PrintPreview the output is properly centered on the page, but when I print the page, the output is shifted down and to the right. After a lot of head-scratching, I determined that the printed image is shifted right by an amount equal to HardMarginX and shifted down by an amount equal to HardMarginY. I then subtracted HardMarginX from Margin.Left and HardMarginY from Margin.Top. With this adjustment the printed page is perfectly centered, but the PrintPreview is now shifted up and to the left. The values for the margins are:
Margins=[Margins Left=50 Right=50 Top=100 Bottom=100]
[HardMarginX]: 25, [HardMarginY]: 50
How can I fix this problem? Thanks for your assistance.
[761 byte] By [
GrandpaB] at [2007-12-24]
Hi back again,
I had a post on the VB Express forum about programmatically changing the paper size and orientation. In that post I whined about this offset problem that I was having. Today, I received a reply from Tall Dude that was a eureka moment. He educated me about the PrintDocument.PrintController.IsPreview option. The problem was solved with the following code snippet.
Dim lMargin As Int32 = e.MarginBounds.X
Dim tMargin As Int32 = e.MarginBounds.Y
If Not PrtDoc.PrintController.IsPreview Then
lMargin -= PrtDoc.DefaultPageSettings.HardMarginX
tMargin -= PrtDoc.DefaultPageSettings.HardMarginY
End If
The code was placed in the PrintDocument.PrintPage event handler. The margins are set to the value in e (the event arguments), but if the outpt is not going to a PrintPreview the HardMargins X and Y are subtracted from these two margins.
The values GrandPaB talked about are available
in VB Express Edition.
There is a 'PrintDocument.OriginAtMargins Property'
that I have not studied closely that may be available
in your version. (I only have VB EE)
It may be useful.