Printing multiple lines on same page

ben_ng

Member
Joined
Sep 13, 2007
Messages
18
Location
Singapore
Programming Experience
1-3
Hi,
been searching for a solution for a few days,but still can't find a good one yet.
I am new to vb .net and currently doing upgrading of vb6 to vb .net.
I have seen this page : http://vbcity.com/forums/faq.asp?fid=15&cat=Printing
and this page :
http://www.vbdotnetheaven.com/UploadFile/mgold/PrintinginVBNET04202005015906AM/PrintinginVBNET.aspx
on how to print from vb .net.

However,what I need is to print multiple lines of various fonts types/sizes on the same page.When I attempted to use multiple printer.printpage() statements,all I got is different lines being printed out to different pages.
How do I modify my code,so that it will allow me to print many lines all on the same page?
Any help is greatly appreciated!
Thanks
 
Hi,
attached my code :
VB.NET:
Imports System.Drawing.Printing
Imports System.Windows.Forms
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Print As New myPrinter
        Print.prt("First line", True, 390, 190, "Arial", 15)
        Print.prt("Another line", True, 390, 190, "Times New Roman", 12)
    End Sub
End Class
Public Class myPrinter
    Friend TextToBePrinted As String
    Friend ssFontName As String
    Friend bbBold As Boolean
    Friend iiFontSize As Integer
    Friend cCoordX As Single
    Friend cCoordY As Single
    Public Sub prt(ByRef txtPrint As String, ByRef bBold As Boolean, ByRef CoordX As Short, _
ByRef CoordY As Short, Optional ByRef sFontName As String = "", Optional ByRef iFontSize As Short = 0)
        TextToBePrinted = txtPrint
                ssFontName = sFontName
        bbBold = bBold
                iiFontSize = iFontSize
                cCoordX = CoordX
        cCoordY = CoordY
                Dim prn As New Printing.PrintDocument
        Using (prn)
            AddHandler prn.PrintPage, AddressOf Me.PrintPageHandler
                        prn.Print()
            RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHandler
                End Using
    End Sub
    Private Sub PrintPageHandler(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs)
        Dim myFont As New Font(ssFontName, iiFontSize)
                Dim drawBrush As New SolidBrush(Color.Black)
                Dim drawPoint As New PointF(cCoordX, cCoordY)
        Dim drawFormat As New StringFormat
        drawFormat.FormatFlags = StringFormatFlags.DirectionVertical
                args.Graphics.DrawString(TextToBePrinted, myFont, drawBrush, drawPoint)
    End Sub
End Class
 
Last edited by a moderator:
.Net printing doesn't work that way, if you call for Print it will print one or more pages, but it won't print one line and stop in the middle of the paper. Have you ever printed from an application, and it wouldn't give you the paper? ("no, you can have it tomorrow when I have finished filling it with all the lines. thank you for your print request, but it isn't efficient." ;))
 
Stack up your lines in a array/collection of strings (I'd use a List(Of String) object), call print when you want to print the page.
 
Stack up your lines in a array/collection of strings (I'd use a List(Of String) object), call print when you want to print the page.
Oh..doesn't sound like a pretty elegant way to solve the problem...hehee...
well,I guess that will have to do for now,unless someone else has something else to add...
Thanks for the prompt reply!:D
This forum rocks!
 
Back
Top