Starnge Behaviour between PrintDocument and PageSetupDialog

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I would welcome any assistance.
In a program I am using the standard PrintDocument, PageSetupDialog and PrintPreView controls. I am attempting to print a screenful of information which covers three A4 printed sheets. The printed format is OK except that the positioning on the page. Changing
the margins in the PageSetupDialog makes it worse.
So I wrote the following code in the Form Load event to see what was going on -
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff
While
</font></font></font><font face="Consolas" size="2" color="#0000ff <font face="Consolas" size="2" color="#0000ff

</font></font><font face="Consolas" size="2" color="#0000ff

</font>
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small True
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <font face="Consolas" size="2 <font face="Consolas" size="2

</font></font><font face="Consolas" size="2

</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small Dim<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
MsgStr <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small As<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small String<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
= <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small String<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small .Empty<font face="Consolas" size="2 <font face="Consolas" size="2


</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#008000; font-size:x-small <span style="font-family:Consolas; color:#008000; font-size:x-small <span style="font-family:Consolas; color:#008000; font-size:x-small find initial PrintDocument value
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <font face="Consolas" size="2 <font face="Consolas" size="2

</font></font><font face="Consolas" size="2

</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small With<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
PrintDocument1.DefaultPageSettings<font face="Consolas" size="2 <font face="Consolas" size="2

MsgStr =
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Before page setup PRINTDOCUMENT - Top Margin:
"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small & .Margins.Top & _<font face="Consolas" size="2 <font face="Consolas" size="2

vbCrLf &
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Bottom Margin: "<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
& .Margins.Bottom & _<font face="Consolas" size="2 <font face="Consolas" size="2

vbCrLf &
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Left Margin: "<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
& .Margins.Left & _<font face="Consolas" size="2 <font face="Consolas" size="2

vbCrLf &
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Right Margin: "<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
& .Margins.Right
MsgBox(MsgStr)
<font face="Consolas" size="2 <font face="Consolas" size="2

</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small End<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small With
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <font face="Consolas" size="2 <font face="Consolas" size="2

</font></font><font face="Consolas" size="2

</font>
<span style="font-family:Consolas; color:#008000; font-size:x-small <span style="font-family:Consolas; color:#008000; font-size:x-small <span style="font-family:Consolas; color:#008000; font-size:x-small find the values after transferring to PageSetupDialog
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <font face="Consolas" size="2 <font face="Consolas" size="2

</font></font><font face="Consolas" size="2

</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small With<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
PageSetupDialog1
.Document = PrintDocument1
.PageSettings = PrintDocument1.DefaultPageSettings
<font face="Consolas" size="2 <font face="Consolas" size="2
MsgStr =
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Before page setup PAGESETUPDIALOG- Top Margin:
"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small & .PageSettings.Margins.Top & _<font face="Consolas" size="2 <font face="Consolas" size="2

vbCrLf &
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Bottom Margin: "<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
& .PageSettings.Margins.Bottom & _<font face="Consolas" size="2 <font face="Consolas" size="2

vbCrLf &
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Left Margin: "<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
& .PageSettings.Margins.Left & _<font face="Consolas" size="2 <font face="Consolas" size="2

vbCrLf &
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Right Margin: "<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
& .PageSettings.Margins.Right
MsgBox(MsgStr)
<font face="Consolas" size="2 <font face="Consolas" size="2

</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small End<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small With
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <font face="Consolas" size="2 <font face="Consolas" size="2

</font></font><font face="Consolas" size="2

</font>
<span style="font-family:Consolas; color:#008000; font-size:x-small <span style="font-family:Consolas; color:#008000; font-size:x-small <span style="font-family:Consolas; color:#008000; font-size:x-small do not change any value in dialog - just click
OK
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <font face="Consolas" size="2 <font face="Consolas" size="2

</font></font><font face="Consolas" size="2

</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small If<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
PageSetupDialog1.ShowDialog = Windows.Forms.<span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small DialogResult<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small .OK
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small Then
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
<font face="Consolas" size="2 <font face="Consolas" size="2

</font></font><font face="Consolas" size="2

</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small End<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small If
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <font face="Consolas" size="2 <font face="Consolas" size="2

</font></font><font face="Consolas" size="2

</font>
<span style="font-family:Consolas; color:#008000; font-size:x-small <span style="font-family:Consolas; color:#008000; font-size:x-small <span style="font-family:Consolas; color:#008000; font-size:x-small find the values after leaving PageSetupDialog

<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <font face="Consolas" size="2 <font face="Consolas" size="2

</font></font><font face="Consolas" size="2

</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small With<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
PageSetupDialog1.PageSettings<font face="Consolas" size="2 <font face="Consolas" size="2

MsgStr =
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "After page setup PAGESETUPDIALOG- Top Margin:
"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small & .Margins.Top & _<font face="Consolas" size="2 <font face="Consolas" size="2

vbCrLf &
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Bottom Margin: "<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
& .Margins.Bottom & _<font face="Consolas" size="2 <font face="Consolas" size="2

vbCrLf &
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Left Margin: "<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
& .Margins.Left & _<font face="Consolas" size="2 <font face="Consolas" size="2

vbCrLf &
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Right Margin: "<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
& .Margins.Right
MsgBox(MsgStr)
<font face="Consolas" size="2 <font face="Consolas" size="2

</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small End<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small With
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <font face="Consolas" size="2 <font face="Consolas" size="2

</font></font><font face="Consolas" size="2

</font>
<span style="font-family:Consolas; color:#008000; font-size:x-small <span style="font-family:Consolas; color:#008000; font-size:x-small <span style="font-family:Consolas; color:#008000; font-size:x-small find the values after transferring back to PageSetupDialog
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <font face="Consolas" size="2 <font face="Consolas" size="2

</font></font><font face="Consolas" size="2

</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small With<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
PrintDocument1.DefaultPageSettings<font face="Consolas" size="2 <font face="Consolas" size="2


</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small Dim<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
Str1 <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small As<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small String<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
= <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "After page setup PRINTDOCUMENT-
Top Margin: "<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small & .Margins.Top & _<font face="Consolas" size="2 <font face="Consolas" size="2

vbCrLf &
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Bottom Margin: "<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
& .Margins.Bottom & _<font face="Consolas" size="2 <font face="Consolas" size="2

vbCrLf &
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Left Margin: "<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
& .Margins.Left & _<font face="Consolas" size="2 <font face="Consolas" size="2

vbCrLf &
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "Right Margin: "<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
& .Margins.Right
MsgBox(Str1)
<font face="Consolas" size="2 <font face="Consolas" size="2

</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small End<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small With
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <font face="Consolas" size="2 <font face="Consolas" size="2

</font></font><font face="Consolas" size="2

</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small End<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small While
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small The results between iterations seem surprising
(keeping all the value in the pagesetupdialog the same and just clicking OK
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small 1st iteration PrintDocument TopMargin was 100,
this transferred to the Pagesetup top margin as 100, displayed as 10mm, on clicking OK the PagesetupDialog gave a top marin of 39. Successive iterations just keep reducing the output value.
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small It seems that the PageSetUpDialog is doing some
form of conversion
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small Any suggestions as to what is happening and how
to overcome?
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small Terry <hr class="sig Terry

View the full article
 
Back
Top