Solved

Simple DrawImage question for PrintDocument

Posted on 2004-10-08
2
844 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

19 Experts available now in Live!

Get 1:1 Help Now