Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > Components & Controls > Reporting / Printing

Reporting / Printing Discussion on output-creation components such as reporting, pdf, etc.

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-28-2009, 3:21 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Oct 2009
Location: Wales
Age: 34
Posts: 6
Reputation: 0
macvic211 is on a distinguished programming path ahead
Unhappy help needed with margins when printing

I have a picturebox which displays a JPEG image (this image has been created using Photoshop to a full A4 size) I have figured out how to print, but when printed, the margins around the image are too large - i need the image to print to a full A4 page with just the printer's default margins.

This is the code I have used to print :

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
PrintDocument1.Print()
End If
End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.DrawImage(Me.PictureBox1.Image, e.MarginBounds)
End Sub


Any help with this problem is much appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-28-2009, 5:05 PM
VB.NET Forum Miyagee
.NET Framework: .NET 2.0
 
Join Date: Nov 2007
Location: Kent, UK
Age: 39
Posts: 497
Reputation: 166
InertiaM I'm the one to askInertiaM I'm the one to askInertiaM I'm the one to askInertiaM I'm the one to askInertiaM I'm the one to askInertiaM I'm the one to ask
Default

Tip - create a print preview option and check it before it's printed - helps to save the planet

Although you believe it's been sized for A4, you'll probably still have to enlarge it to fit the page. For example:-

Code:
Option Explicit On
Option Strict On

Imports System.Drawing.Printing

Public Class Form1

    Public WithEvents pdPrinter As New PrintDocument

    Private Sub TestPrintPreview(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

        Using ppvwPrinter As New PrintPreviewDialog
            With ppvwPrinter
                .Document = pdPrinter
                .Width = Screen.PrimaryScreen.Bounds.Width
                .Height = Screen.PrimaryScreen.Bounds.Height
                .PrintPreviewControl.Zoom = 0.66
                .ShowDialog()
            End With
        End Using
    End Sub

    Private Sub Begin_Printing(ByVal sender As System.Object, _
    ByVal e As System.Drawing.Printing.PrintEventArgs) _
     Handles pdPrinter.BeginPrint
        pdPrinter.DocumentName = "Test Document"
        pdPrinter.PrintController = New Printing.StandardPrintController()
    End Sub

    Private Sub Test_PrintPage(ByVal sender As System.Object, _
    ByVal e As PrintPageEventArgs) Handles pdPrinter.PrintPage
        With e.Graphics
            .PageUnit = GraphicsUnit.Millimeter

            .DrawImage(PictureBox1.Image, 0, 0, Convert.ToInt32((e.PageSettings.PaperSize.Width / 100) * 25.4), Convert.ToInt32((e.PageSettings.PaperSize.Height / 100) * 25.4))
        End With
    End Sub

End Class
If you find that the PrintPreview and the actual print are not in the same place, look at this thread
__________________
Always parameterize your queries - read more here
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-01-2009, 4:44 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Oct 2009
Location: Wales
Age: 34
Posts: 6
Reputation: 0
macvic211 is on a distinguished programming path ahead
Default

Thanks for the quick response, but unfortunately, I'm still having problems! The jpeg image that needs to be printed is definitely sized to A4. I tried adding a print preview and page setup as you suggested and got the image to print centrally by altering the margins in the page setup from 10 to 3mm around each side. Is there a way to alter this by using code so that 3mm is the default setting of the program? The reason for this is that I do not want a print preview/page setup on the end program as it needs to run as simply as possible. Sorry if I'm asking simple questions, but as I said, I am just learning!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-01-2009, 5:52 PM
VB.NET Forum Miyagee
.NET Framework: .NET 2.0
 
Join Date: Nov 2007
Location: Kent, UK
Age: 39
Posts: 497
Reputation: 166
InertiaM I'm the one to askInertiaM I'm the one to askInertiaM I'm the one to askInertiaM I'm the one to askInertiaM I'm the one to askInertiaM I'm the one to ask
Default

Code:
        With pdPrinter
            .DefaultPageSettings.Margins.Left = Convert.ToInt32((3.0 / 25.4) * 100)
        End With
should work.

The main reason for using the Print Preview is to see what it's going to do. Once you have it done, just convert the code to print normally
__________________
Always parameterize your queries - read more here
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 12-06-2009, 6:52 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Oct 2009
Location: Wales
Age: 34
Posts: 6
Reputation: 0
macvic211 is on a distinguished programming path ahead
Talking

Many thanks for the help, I have now solved the printing problem!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 1:44 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.