Solved

printing using the print dialogue

Posted on 2006-11-05
8
302 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
[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
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

695 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