Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Simple DrawImage question for PrintDocument

Posted on 2004-10-08
2
Medium Priority
?
906 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

610 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