Solved

Simple DrawImage question for PrintDocument

Posted on 2004-10-08
2
857 Views
Last Modified: 2012-08-13
I'd like to print an image stretched to the maximum available space on a page in PrintDocument.  The image is stored as type Image

What I'd like to see is code that will take an Image and call e.Graphics.DrawImage in such a way that the image takes up all the available space (remember to take into account e.marginbounds)

Alternatively, if there is a better method, I'd love to see it, as long as it works.
0
Comment
Question by:masoncooper
2 Comments
 
LVL 28

Accepted Solution

by:
iboutchkine earned 50 total points
ID: 12259832
Try this

Imports System.Drawing.Printing

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
#End Region

    'Sub for printing graphic
    Private Sub PrintGraphic(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
        ' Create the graphic using DrawImage
        'DrawImage expands graphic to the max size of the paper
        ev.Graphics.DrawImage(Image.FromFile(TextBox1.Text), ev.Graphics.VisibleClipBounds)
        ' Specify that this is the last page to print
        ev.HasMorePages = False
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Print using an error handler to catch problems
        Try
            AddHandler PrintDocument1.PrintPage, AddressOf Me.PrintGraphic
            PrintDocument1.Print()   'print graphic
        Catch ex As Exception  'catch printing exception
            MessageBox.Show("Sorry--there is a problem printing",  ex.ToString())
        End Try
    End Sub
End Class
0
 
LVL 2

Author Comment

by:masoncooper
ID: 12259925
Perfect! Thanks, the e.Graphics.VisibleClipBounds was exactly what I was looking for.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 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