esposito
Centurion
Hello, I know how to print out text on paper in VB.NET but I still have to learn how to print out a picture, e.g. the image loaded in a picturebox.
Can you help me?
TIA
Can you help me?
TIA
Private Sub PDoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PDoc.PrintPage
'setup the bmp image
Dim bmp As Bitmap = New Bitmap(System.Drawing.Image.FromFile(Application.StartupPath & "\Data\R001.bmp"), pnlDrawing.Width, pnlDrawing.Height)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim lbl As Label
Dim strFormat As New System.Drawing.StringFormat()
'add the resistor values
For Each lbl In Me.pnlDrawing.Controls
If lbl.Text <> Nothing Then
strFormat.Alignment = StringAlignment.Center
Dim lblTextF As New RectangleF(lbl.Location.X, lbl.Location.Y, lbl.Width, lbl.Height)
g.DrawString(lbl.Text, lbl.Font, New SolidBrush(Color.Black), lblTextF, strFormat)
'add the resistor colored bands
Else
Dim lblBandF As New RectangleF(lbl.Location.X, lbl.Location.Y, lbl.Width, lbl.Height)
lbl.BackgroundImage = lbl.ImageList.Images(lbl.ImageIndex)
g.DrawImage(lbl.BackgroundImage, lblBandF)
End If
Next
'print bmp
Dim R As Rectangle
Dim PWidth, PHeight, PictLeft, PictTop As Integer
PWidth = bmp.Width
PHeight = bmp.Height
With PDoc.DefaultPageSettings.PaperSize
PictLeft = (PDoc.DefaultPageSettings.PaperSize.Width - PWidth) / 2
PictTop = 130
End With
R = New Rectangle(PictLeft, PictTop, PWidth, PHeight)
e.Graphics.DrawImage(bmp, R)
Dim boldFont As New Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Point)
'Print Header
Dim TitleF As New System.Drawing.SizeF()
TitleF = e.Graphics.MeasureString("Resistor color code and value", boldFont)
e.Graphics.DrawString("Resistor color code and value", boldFont, Brushes.Black, (PDoc.DefaultPageSettings.PaperSize.Width - TitleF.Width) / 2, 100)
bmp.Dispose()
boldFont.Dispose()
End Sub