Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to print PictureBox.Image with String Using Class

How to print PictureBox.Image with String Using Class

How to print PictureBox.Image with String Using Class

I hope the title is enough to understand my problem, I just want that if the button is click, i want to print an image with some text using class,

just like this in the picture below (example print)

This is my Print.vb (Class)

CODE --> Class

Public Class Print
    Private Shared Lines As New Queue(Of String)
    Private Shared _myfont As Font
    Private Shared prn As Printing.PrintDocument
    Private Shared G As Graphics
    Public Shared Str As String
    Private Shared PhotoBox As New Rectangle(5, 5, 150, 200)
    Public Shared Photo As Image

    Shared Sub New()
        _myfont = New Font("Courier New",
                  8, FontStyle.Regular, GraphicsUnit.Point)
        prn = New Printing.PrintDocument

        AddHandler prn.PrintPage, AddressOf PrintPageHandler

    End Sub
    Public Shared Sub Print(ByVal text As String, image As Image)
        Dim linesarray() = text.Split(New String() _
            {Environment.NewLine}, StringSplitOptions.None)

        'EmpPhoto = Photo
        For Each line As String In linesarray
    End Sub
    Private Shared Sub PrintPageHandler(ByVal sender As Object,
        ByVal e As Printing.PrintPageEventArgs)

        Dim sf As New StringFormat()
        Dim vpos As Single = e.PageSettings.HardMarginY

        If Photo IsNot Nothing Then
            G.DrawImage(Photo, New Rectangle(PhotoBox.X + 1, PhotoBox.Y + 1, PhotoBox.Width - 1, PhotoBox.Height - 1))
        End If
        Do While Lines.Count > 0
            Dim line As String = Lines.Dequeue
            Dim sz As SizeF = e.Graphics.MeasureString(
                line, _myfont, e.PageSettings.Bounds.Size, sf)

            Dim rct As New RectangleF(
                e.PageSettings.HardMarginX, vpos,
                e.PageBounds.Width - e.PageSettings.HardMarginX * 2,
                e.PageBounds.Height - e.PageSettings.HardMarginY * 2)

            e.Graphics.DrawString(line, _myfont, Brushes.Black, rct)

            vpos += sz.Height
            If vpos > e.PageSettings.Bounds.Height -
                e.PageSettings.HardMarginY * 2 Then
                e.HasMorePages = True
                Exit Sub
            End If
    End Sub
End Class 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close