Solved

printing using the print dialogue

Posted on 2006-11-05
8
290 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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

14 Experts available now in Live!

Get 1:1 Help Now