Solved

How do I print in Visual Basic .NET 2005

Posted on 2006-07-10
6
188 Views
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.
0
Comment
Question by:OsirisJa
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:jrscherer
Comment Utility
Hi  OsirisJa

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

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21909919.html

Jack.net
0
 

Author Comment

by:OsirisJa
Comment Utility
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

0
 
LVL 9

Expert Comment

by:jrscherer
Comment Utility
I think this is a good article to get some basics of printing and print dialog.
http://www.vb-helper.com/howto_net_print_and_preview.html
Jack.net
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:OsirisJa
Comment Utility
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
0
 
LVL 9

Accepted Solution

by:
jrscherer earned 500 total points
Comment Utility
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
0
 

Author Comment

by:OsirisJa
Comment Utility
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.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

10 Experts available now in Live!

Get 1:1 Help Now