How to set the printdocuments pagesettings to A4 without calling the PageSetup Dialog. VIsual Basics 2010 express

  • Thread starter Thread starter Tasipeka
  • Start date Start date
T

Tasipeka

Guest
I've spend a whole day trying to set the PrintDocuments page settings to use A4 rather then always have to open a PrintSetup Dialog to set the page settings then and assign its PageSettings to PrintDocument. How can I insert the settings as permanenent to the PrinDocument

//Open PageSetup Dialog to set page settings (A4)

PageSetUpDialog1.PageSettings = PrintDocument1.DefaultPageSettings

If PageSetUpDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
PrintDocument1.DefaultPageSettings = PageSetUpDIalog1.PageSettings
End If

e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
' Print a string at the origin
Dim pFont As Font
pFont = New Font("Comic Sans MS", 20)
e.Graphics.DrawString("ORIGIN", pFont, Brushes.Black, 0, 0)
' Read margins into local variables
Dim Lmargin, Rmargin, Tmargin, Bmargin As Integer
With printdoc1.DefaultPageSettings.Margins
Lmargin = .Left
Rmargin = .Right
Tmargin = .Top
Bmargin = .Bottom
End With
' Calculate the dimensions of the printable area
Dim PrintWidth, PrintHeight As Integer
With printdoc1.DefaultPageSettings.PaperSize
PrintWidth = .Width - Lmargin - Rmargin
PrintHeight = .Height - Tmargin - Bmargin
End With
' Now print the rectangle
Dim R As Rectangle
R = New Rectangle(Lmargin, Tmargin, PrintWidth, PrintHeight)
e.Graphics.DrawRectangle(Pens.Blue, R)


I always have to open the PageSetup Dialog only to st the papersize to A4. How can I hard code this part into the PrintDocument so it would never change

Continue reading...
 
Back
Top