How do I print in Visual Basic .NET 2005

Posted on 2006-07-10
Medium Priority
Last Modified: 2010-04-23
I have a program that processes a lot of information. It produces the results in labels and text boxes from variables.

I would like a formatted printout of the information from the variables. How Do I do this?

Thank you all very much.
Question by:OsirisJa
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
  • 3

Expert Comment

ID: 17078676
Hi  OsirisJa

Check here for some very basics on printing in VS.Net



Author Comment

ID: 17078901
I apologize, but I am lost.

Could you help me with a subroutine that displays the select printer dialog and allows printing to a Printer on the system?

I would also like the code required to print and then the foll examples

Print the contents of a variable to the page
Priint a text string to the page
Print Centred text to the page
and any other things important to know.

Thank you very much


Expert Comment

ID: 17078985
I think this is a good article to get some basics of printing and print dialog.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 17080673
Thats is not using VB.NET 2005 and it does not demonstrate how to

Print the contents of a variable to the page
Priint a text string to the page
Print Centred text to the page
and any other things important to know.

Please help me directly address my question and not point me to a random link.

Thank you

Accepted Solution

jrscherer earned 1500 total points
ID: 17087664
here are some examples

    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim verticalLocation As Single = 100.0 ' one inch from left border
        Dim horizontalLocation As Single = 200.0 ' 2 inches from top border

        Dim MyFont As New Font("Arial", 10, FontStyle.Regular)
        ' prepare the variable Integer1 to be printed
        e.Graphics.DrawString(Variable1.ToString, MyFont, Brushes.Black, horizontalLocation, verticalLocation)

        verticalLocation = 150.0

        ' prepare the variable String1 to be printed
        e.Graphics.DrawString(Variable1.ToString, MyFont, Brushes.Black, horizontalLocation, verticalLocation)

        verticalLocation = 200.0

        ' center the string ad midscreen
        ' first measure the with of the string when printed
        Dim stringWidth As Single = e.Graphics.MeasureString(String1, MyFont).Width

        ' then locate the midpoint of the paper
        Dim MidPoint As Single = CSng(e.PageBounds.Left + (e.PageBounds.Width / 2))

        ' then prepare printing of the string centered into the page, respecting page setting of the printer setting, such as paper size and orientation
        e.Graphics.DrawString(Variable1.ToString, MyFont, Brushes.Black, MidPoint - (stringWidth / 2), verticalLocation)
        ' another string formatting method follows
        ' draw a string and use the GDI+ string formatter
        Dim frm As New StringFormat
        frm.Alignment = StringAlignment.Center
        frm.LineAlignment = StringAlignment.Center

        ' define a rectangle to draw a centered text
        Dim Rec As RectangleF
        Rec.Location = New PointF(horizontalLocation, 250)
        Rec.Size = New Size(200, 200)

        ' draw the rectangle as reference
        e.Graphics.DrawRectangle(Pens.Gray, Rec.X, Rec.Y, Rec.Width, Rec.Height) ' no overload exists fro RectangleF

        ' draw the centered text into box
        e.Graphics.DrawString(String1, MyFont, Brushes.Black, Rec, frm) ' frm does the formatting to the rectangle

  End Sub

Hope this helps to find the way into printing  Jack.net

Author Comment

ID: 17105950
Thank you very much. It wasn't exactly what I wanted, but I was able to use pieces from it and it gave me a general idea.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

649 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