Print .jpeg in

Posted on 2009-04-16
Last Modified: 2013-11-26
I want to print a .jpeg file (e.g c:\test.jpg) to the default printer from a push button in I don't want to see dialog boxes.
Question by:adimit
    LVL 48

    Accepted Solution

    You can do something like this:

        Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
            Using printer As New Printing.PrintDocument
                AddHandler printer.PrintPage, AddressOf PrintImage
            End Using
        End Sub
        Private Sub PrintImage(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs)
            Dim img As Image = Image.FromFile("c:\ImageToPrint.jpg")
            e.Graphics.DrawImage(img, 0, 0)
        End Sub

    Open in new window


    Author Comment

    The above code works. How do I format the printout in terms of margins and orientations
    LVL 48

    Assisted Solution

    In the PrintImage sub you can change the position, like this:

    e.Graphics.DrawImage(img, 50, 50)
    And the orientation you can do this way:

    Using printer As New Printing.PrintDocument
          printer.DefaultPageSettings.Landscape = True

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now