Solved

printing using the print dialogue

Posted on 2006-11-05
8
299 Views
Last Modified: 2010-04-23
I'm trying to learn how to print using the print dialogue from VB.Net 2005

My biggest and current problem is how to over-ride the margins, such as using something akin to a "page setup" feature.  I don't see that in the print dialogue.

Currently, using code like this:

    Private Sub mDoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles mDoc.PrintPage
        Dim xPos As Single = e.MarginBounds.Left
        Dim yPos As Single = e.MarginBounds.Top
        Dim lineHeight As Single = mFont.GetHeight(e.Graphics)
        Static l As Integer
        Dim intCt As Integer
    End Sub

(which I "borrowed" from someone here on EE   :-)  )

my documents have a 1 1/2 " margin at the top and about 1 1/4" margin to the left.
So apparently that's the default for the printer.

How can I use some kind of page setup feature to over-ride those and also, but not as important, to set font choices, etc.?

Thanks
0
Comment
Question by:g_johnson
  • 3
  • 2
8 Comments
 
LVL 5

Assisted Solution

by:maralans
maralans earned 100 total points
ID: 17879291


Private Sub btnPageSetup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPageSetup.Click
        Dim psd As New PageSetupDialog()
        With psd
            .Document = mdoc
            .PageSettings = mdoc.DefaultPageSettings
        End With

        If psd.ShowDialog = Windows.Forms.DialogResult.OK Then
            mdoc.DefaultPageSettings = psd.PageSettings
        End If
    End Sub
0
 
LVL 5

Accepted Solution

by:
DEEPESH earned 400 total points
ID: 17879365
These are some points i jotted down from Microsft Book, see if it may help you
The PrintPage event is the main event involved in printing documents. To actually send content to the printer, you must handle this event and provide code to render the content in the PrintPage event handler

mainly there are two properties of PrintPageEventArgs

MarginBounds which Gets the Rectangle object that represents the portion of the page within the margins
PageSettings which Gets or sets the PageSettings object for the current page

The MarginBounds and PageBounds properties represent areas of the page surface. You can specify printing to occur inside the margin bounds of the page by calculating printing coordinates based on the MarginBounds rectangle. Printing that is to take place outside the margin bounds, such as headers or footers, can be specified by calculating the printing coordinates based on the PageBounds rectangle. As with painting to the screen, print coordinates are in pixels by default.

Sample code
Dim ArrayCounter As Integer = 0
' This method handles a PrintDocument.PrintPage event. It assumes
' an array of strings called myStrings() has been declared and
' populated elsewhere in the application. It also assumes a font
' for printing has been initialized and called myFont
Private Sub PrintStrings(sender As Object, e As _
   PrintPageEventArgs)
   ' Declares the variables that will be used to keep track of
   ' spacing and paging
   Dim LeftMargin As Single = e.MarginBounds.Left
   Dim TopMargin As Single = e.MarginBounds.Top
   Dim MyLines As Single = 0
   Dim YPosition As Single = 0
   Dim Counter As Integer = 0
   Dim CurrentLine As String
   ' Calculate the number of lines per page.
   MyLines = e.MarginBounds.Height / _
      myFont.GetHeight(e.Graphics)
   ' Prints each line of the file, but stops at the end of a page
   While Counter < MyLines And ArrayCounter <= _
      myStrings.GetUpperBound(0)
      CurrentLine = myStrings(ArrayCounter)
      YPosition = TopMargin + Counter * _
         myFont.GetHeight(e.Graphics)
      e.Graphics.DrawString(CurrentLine, myFont, Brushes.Black, _
         LeftMargin, YPosition, New StringFormat())
      Counter += 1
      ArrayCounter += 1
   End While
   
   ' If more lines exist, print another page.
   If Not (ArrayCounter = myStrings.GetUpperBound(0)) Then
      e.HasMorePages = True
   Else
      e.HasMorePages = False
   End If
End Sub


0
 
LVL 5

Expert Comment

by:DEEPESH
ID: 17987537
Any comment on it g_johnson
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 4

Author Comment

by:g_johnson
ID: 17991933
Hi, Deepesh.  Unfortunately, as so often happens, I haven't had a chance to test yet.  Now the computer involved is "down."  I will get to it, though.  I'm sure the comments here are valid but I need to do a comprehensive test.  Thanks for your patience.
0
 
LVL 4

Author Comment

by:g_johnson
ID: 18143894
Please leave this open if you can.  I am juggling many projects right now and have not had a chance to try these solutions.
0
 
LVL 4

Author Comment

by:g_johnson
ID: 18384983
sorry it took so long -- i had to force myself to test things last night.
Thanks -- I have a much better understanding of it now.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

803 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