This example requires you have a placed an ImagePrintDocument onto your form. It demonstrates printing one image to the printer, and scaling it to fit the page.
C# |
|
---|
myImagePrintDocument.Image = myImageViewer.Image; myImagePrintDocument.ScaleMode = PrintScaleMode.FitToMargins; myImagePrintDocument.Print(); |
Visual Basic |
|
---|
myImagePrintDocument.Image = myImageViewer.Image myImagePrintDocument.ScaleMode = PrintScaleMode.FitToMargins myImagePrintDocument.Print() |
This example demonstrates how to print all images in a WorkspaceViewer to the printer while letting the user specify page and printer settings. By handling the PrintPage and AfterPrintPage events, it also demonstrates how to customize individual pages that are printed. This example uses a
WorkspaceViewer,
ImagePrintDocument,
PageSetupDialog, and
PrintDialog in a WinForms application. The Document Property in the PageSetupDialog and PrintDialog must be set to the ImagePrintDocument.
C# |
|
---|
private void imagePrintDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { //allows the user to customize page fitting for each page that's printed if (MessageBox.Show(this, "Do you wish to fit this image to the page?", "Specify Page Fitting", MessageBoxButtons.YesNo) == DialogResult.Yes) imagePrintDocument1.ScaleMode = PrintScaleMode.FitToMargins; else imagePrintDocument1.ScaleMode = PrintScaleMode.None; }
private void imagePrintDocument1_AfterPrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { //draws a watermark on the page e.Graphics.DrawString("This is a test watermark.", new Font("Arial", 18), new SolidBrush(Color.Black), 0, 0); }
private void btnPrintImage_Click(object sender, System.EventArgs e) { //lets the user set the printer options if (printDialog1.ShowDialog(this) == DialogResult.OK) { //set all images from the image collection imagePrintDocument1.SetImagesFromImageCollection(workspaceViewer1.Images); imagePrintDocument1.Print(); } }
private void btnPageSetup_Click(object sender, System.EventArgs e) { //lets the user modify the page settings such as margins pageSetupDialog1.ShowDialog(this); } |
This example demonstrates how to print all images in a WorkspaceViewer to the printer while letting the user specify page and printer settings. By handling the PrintPage and AfterPrintPage events, it also demonstrates how to customize individual pages that are printed. This example uses a
WorkspaceViewer,
ImagePrintDocument,
PageSetupDialog, and
PrintDialog in a WinForms application. The Document Property in the PageSetupDialog and PrintDialog must be set to the ImagePrintDocument.
Visual Basic |
|
---|
Private Sub imagePrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles imagePrintDocument1.PrintPage If MessageBox.Show(this,"Do you wish to fit this image to the page?","Specify Page Fitting",MessageBoxButtons.YesNo) = DialogResult.Yes Then imagePrintDocument1.ScaleMode = PrintScaleMode.FitToMargins Else imagePrintDocument1.ScaleMode = PrintScaleMode.None End If End Sub
Private Sub imagePrintDocument1_AfterPrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles imagePrintDocument1.AfterPrintPage e.Graphics.DrawString("This is a test watermark.", New Font("Arial", 18), New SolidBrush(Color.Black), 0, 0) End Sub
Private Sub btnPrintImage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrintImage.Click If printDialog1.ShowDialog(Me) = DialogResult.OK Then imagePrintDocument1.SetImagesFromImageCollection(workspaceViewer1.Images) imagePrintDocument1.Print() End If End Sub
Private Sub btnPageSetup_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPageSetup.Click pageSetupDialog1.ShowDialog(Me) End Sub
|
Comments