Solved

Simple DrawImage question for PrintDocument

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with creating multiple xml files from one xml file using VB.NET 6 38
More on Time zones in vb 2010 12 37
Advice in Xamarin 21 52
Exit the loop 4 34
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

911 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

16 Experts available now in Live!

Get 1:1 Help Now