Printing With Custom Paper Size

G

Guest

Hello all! I am trying to set up my app to print with a custom paper size,
but it keeps failing with the following error:
PaperSize cannot be changed unless the Kind property is set to Custom.
On the line that reads:M_MiniLabel.DefaultPageSettings.PaperSize.Height = 2000
I thought that I was setting the Kind to Custom in the row above. If anybody
has any input this would be greatly appreciated. Code below.

Thank You
Kevin


Imports System.Drawing.Printing

Public Class Form1
Private WithEvents M_MiniLabel As PrintDocument
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
M_MiniLabel = New PrintDocument
PageSetupDialog1.Document = M_MiniLabel
PrintDialog.ShowDialog()
M_MiniLabel.DefaultPageSettings.PaperSize.RawKind = 0
MsgBox(M_MiniLabel.DefaultPageSettings.PaperSize.Kind.ToString)
M_MiniLabel.DefaultPageSettings.PaperSize.Height = 2000
M_MiniLabel.DefaultPageSettings.PaperSize.Width = 4000
PrintDialog.AllowPrintToFile = False
M_MiniLabel.PrinterSettings = PrintDialog.PrinterSettings
M_MiniLabel.OriginAtMargins = True
M_MiniLabel.Print()
End Sub

Private Sub M_MiniLabel_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles M_MiniLabel.PrintPage
Dim font As New Drawing.Font("Times New Roman", 48,
FontStyle.Regular, GraphicsUnit.Point)
Dim format As New StringFormat
format.Alignment = StringAlignment.Near
Dim rec As New System.Drawing.RectangleF(2, 2, 4, 2)
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
e.Graphics.DrawString("test", font, Brushes.Black, 1, 10, format)
e.HasMorePages = False
End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top