Is it possible to print an image using PrintDocument Control? Yes, it is. Basic formula: How does it work? I'll give you some samples. First sample will use an image from a file that its path is c:\logo.png. Let's set UI design. I added a button and a PrintDocument into a Form as below. Code: Imports System.Drawing.Printing Public Class Form1 Private Sub Button1_Click(sender As Object , e As EventArgs ) Handles Button1.Click PrintDocument1.Print() End Sub Private Sub PrintDocument1_PrintPage(sender As Object , e As PrintPageEventArgs ) _ Handles PrintDocument1.PrintPage Dim newImage As Image = Image .FromFile( "c:\logo.png" ) e.Graphics.DrawImage(newImage, 50, 50) End Sub End Class Run and click the button to print. Result: (I'm using pdf printer) What if the image is from a PictureBox control image? You can simply change the image object with PictureBox Image property as below. Private Sub PrintDocument1_PrintPage(sender As Object , e As PrintPageEventArgs ) _ Handles PrintDocument1.PrintPage e.Graphics.DrawImage(PictureBox1.Image, 50, 50) End Sub Run and result will similar: The default setting will print the original size of the image. However, we can set manually the width and height of the image by syntax below. Now, let's try to set image width = 100 and height = 50. Private Sub PrintDocument1_PrintPage(sender As Object , e As PrintPageEventArgs ) _ Handles PrintDocument1.PrintPage e.Graphics.DrawImage(PictureBox1.Image, 50, 50, 100, 50) End Sub Run and result will be: Read also other related articles: Printing tutorial with PrintDocument Control
Sumber http://rani-irsan.blogspot.com
pop
Rabu, 12 Agustus 2020
Vb.Net: Printing Image With Printdocument Control
Diterbitkan Agustus 12, 2020
Artikel Terkait
- Hi Coders, Almost all database application needs report and printing features. What d
- Hi everyone!! This article wants to show you how to create a connection to MySQL database
- To support you in understanding this topic, please read also these articles: How to conn
- On previous articles we discussed: How to connect VB.NET to MySQL database How
- I was working with Visual Studio 2005 and Crystal Report and the requirement is to expor
- Hi There, It's me again. Continue from this article: we.com/search?q=vbnet-introducing-p
Langganan:
Posting Komentar (Atom)
EmoticonEmoticon