Print Issue
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts
Page 1 of 1
Hello guys,
Was wondering if someone could help me. I am trying to use pagesetup and printdocument and printsetupdialog all at once.
What i want is to be able to do change settings using pagesetup and apply this to my printdocument and then print this using printsetup
HOWEVER any code i try i have this weird error where every time i click a dialog it just opens anouther instance of itsself.
Could someone give me example code of how to do this please.
Was wondering if someone could help me. I am trying to use pagesetup and printdocument and printsetupdialog all at once.
What i want is to be able to do change settings using pagesetup and apply this to my printdocument and then print this using printsetup
HOWEVER any code i try i have this weird error where every time i click a dialog it just opens anouther instance of itsself.
Could someone give me example code of how to do this please.
Hello,
Welcome to the frustrating world of printing from winforms lol
I'm not sure how to best help you on this but I can point you in the direction of some excellent resources that may help you:
https://docs.microsoft.com/en-us/dotnet ... nt-support
And a good example of using the pagesetupdialog:
https://msdn.microsoft.com/en-us/librar ... -snippet-2
If possible could you post your code/source-files so I can take a look and try and find where your problem is.
..and welcome to the site
Welcome to the frustrating world of printing from winforms lol
I'm not sure how to best help you on this but I can point you in the direction of some excellent resources that may help you:
https://docs.microsoft.com/en-us/dotnet ... nt-support
And a good example of using the pagesetupdialog:
https://msdn.microsoft.com/en-us/librar ... -snippet-2
If possible could you post your code/source-files so I can take a look and try and find where your problem is.
..and welcome to the site

Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
Code: Select all
Private Sub QR_Client_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PrintDocument1.PrinterSettings = PageSetupDialog1.PrinterSettings
PageSetupDialog1.Document = PrintDocument1
End Sub
Private Sub XylosButton2_Click(sender As Object, e As EventArgs) Handles XylosButton2.Click
Try
PageSetupDialog1.PageSettings = PrintDocument1.DefaultPageSettings
PageSetupDialog1.PrinterSettings = PrintDocument1.PrinterSettings
If PageSetupDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
PrintDocument1.PrinterSettings = PageSetupDialog1.PrinterSettings
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub XylosButton1_Click(sender As Object, e As EventArgs) Handles XylosButton1.Click
Try
PrintDocument1.PrinterSettings = PrintDocument1.PrinterSettings
PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings()
PrintDocument1.Print()
Catch ex As Exception
MsgBox("Printing Problem" & Chr(13) & ex.Message, MsgBoxStyle.Exclamation)
End Try
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Using bmp As Bitmap = New Bitmap(QRCode.Image.Width, QRCode.Image.Height)
Dim rect As New Rectangle(0, 0, QRCode.Image.Width, QRCode.Image.Height)
Me.DrawToBitmap(bmp, rect)
Dim l, t, w, h As Integer
Dim ratio As Single = CSng(bmp.Width / bmp.Height)
If ratio > e.MarginBounds.Width / e.MarginBounds.Height Then
w = e.MarginBounds.Width
h = CInt(w / ratio)
t = CInt(e.MarginBounds.Top + (e.MarginBounds.Height / 2) - (h / 2))
l = e.MarginBounds.Left
Else
h = e.MarginBounds.Height
w = CInt(h * ratio)
l = CInt(e.MarginBounds.Left + (e.MarginBounds.Width / 2) - (w / 2))
t = e.MarginBounds.Top
End If
e.Graphics.DrawImage(bmp, l, t, w, h)
End Using
End Sub
I Dont really know how to explain the issue. Baysically. The print dialog shows up fine. But anytime i click in it at all even blank areas it just opens anouther print dialog
Not sure what's causing the problem, the following code works fine for me:
Code: Select all
Private Sub XylosButton2_Click(sender As Object, e As EventArgs) Handles XylosButton2.Click
Try
PageSetupDialog1.PageSettings = PrintDocument1.DefaultPageSettings
PageSetupDialog1.PrinterSettings = PrintDocument1.PrinterSettings
If PageSetupDialog1.ShowDialog = DialogResult.OK Then
PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
PrintDocument1.PrinterSettings = PageSetupDialog1.PrinterSettings
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023