Solved

Simple DrawImage question for PrintDocument

Posted on 2004-10-08
2
872 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to repeat the data 4 41
VB.NET System.NullReferenceException 1 40
vb.net datagrid point 4 31
ASP.NET Load html part first, then start function 2 37
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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