Printing a multicolumn listview

Cujo

Member
Joined
Feb 6, 2005
Messages
8
Location
Connecticut
Programming Experience
3-5
Anyone have a suggestion on the best way to print a multicolumn listview?

Reason: I have a small routine that reads a text file (a plotting log). Each line is a separate entry into the log. I process the text file and then spit out a "report" to a listview that has the client's job number, the number of plots done for the month, and the cost.

I would like to take this listview data and print it so that I can include it in my end of month documentation.

Again any suggestions? Oh just to let someone know I tried using a richtextbox and that was fine except I wanted everything lined up in columns for easy reading.

Thanks
CuJo
 
same here

I have text for 'transaction', 'amount' and 'date' perfectly lined
up in columns, using LSET and Lucinda Console font, but the
DrawString method ignores my spacing and uses proportional
spacing. Any help out there?
---------------------------------------------------

My code:
------------------------

PrivateSub PrintText(ByVal sender AsObject, _
ByVal ev As PrintPageEventArgs)

'Use DrawString to create text in a Graphics object

ev.Graphics.DrawString(txtPrintBuff.Text, New Font("Lucinda Console", _

11, FontStyle.Regular), Brushes.Black, 60, 60)

' Specify that this is the last page to print

ev.HasMorePages = False

EndSub

PrivateSub PrintTry()

' Print using an error handler to catch problems

Try

' Declare PrintDoc variable of type PrintDocument

Dim PrintDoc AsNew PrintDocument

AddHandler PrintDoc.PrintPage, AddressOfMe.PrintText

PrintDoc.Print()
'print text

Catch ex As Exception 'catch printing exception

MessageBox.Show("Sorry--there is a problem printing", _

ex.ToString())

EndTry

EndSub'PrintTry

 
Last edited:
Kulrom (and Cujo), I don't have the solution perfected yet, but it looks like the answer is in the VB Help topic "Formatting Text", "Setting Tab Stops". (Did Kulrom get involved because this problem has aged itself out of the forum system?) Regards to you, too.
 
Kulrom- I may have made a mistake joining Cujo's thread... I am trying to print from a textbox, not a listview, keeping data lined up vertically, that is, not have proportional spacing. I want something like 10 characters per inch consistently, as with an old dot matrix printer.


Printout is:

borrowed $5.00 05-14-2005
paid $2.00 06-20-2005
borrowed $10.00 07-04-2005

Printout should be:

borrowed___$5.00___05-14-2005
paid_______$2.00___06-20-2005
borrowed__$10.00___07-04-2005

Don't know if it shows correctly, but I'm trying to line up the columns. The underscores would be spaces in my ideal printout.
 
Last edited:
Ok guys, i'm preparing an example of tabularPrinting and i'll send you the project as soon as possible. Mainly, it should look like (normaly after you get separated all these strings among each other):

VB.NET:
'assuming that X1, X2 etc. are properly declared integers
X1 = PrintDocument1.DefaultPageSettings.Margins.Left
		With PrintDocument1.DefaultPageSettings
			pageWidth = .PaperSize.Width - _
				    .Margins.Left - _
				    .Margins.Right
			pageHeight = .PaperSize.Height - _
						 .Margins.Top - _
						 .Margins.Bottom
		End With
		X2 = X1 + 100
		X3 = CInt(X2 + pageWidth * 0.6)
		W1 = X2 - X1
		W2 = X3 - X2
		W3 = pageWidth - W1 - W2
now you can proceed with printing ... as i told you i'll make a demo (first occasion when i'll have advantage time)

Regards ;)
 
I've been away from pc for months. But finally got printing to work as I wanted earlier this year. Used example from HELP. This got refomatted when I pasted it in here, some long lines wrapped, beware. Hope this helps.
======================================================


Imports System.drawing
Imports System.drawing.printing
'This program has one form, with one button.
'
'This code almost exactly matches the "Setting Tab Stops" example
' in help topic "Formatting Text"
'AND WILL LINE UP PRINTED DATA IN COLUMNS <<<<<<<<<<<<<<
Public Class Form1
Inherits System.Windows.Forms.Form
'my header
Public myText As String = Now & "..." & _
" myTabs = 100, 100, 150" & _
ControlChars.CrLf & ControlChars.CrLf
Public mystringformat As New StringFormat
'note - tab array enclosed in braces (or curly brackets), not parentheses
Public mytabs As Single() = {100, 100, 150} '100, 100, 150 of WHAT?
'help topic for stringFormat.SetTabStops says spaces, but is obviously wrong.
Public mysolidBrush As New SolidBrush(Color.FromArgb(255, 0, 0, 255))
' in the "Lucida console" font, all characters are the same width,
' i.e., not proportional, but any font like Arial or whatever should be OK.
Public myfontFamily As New FontFamily("Lucida Console")
Public myfont As New Font(myfontFamily, 10, FontStyle.Regular, _
GraphicsUnit.Point)
Public myRect As New Rectangle(20, 20, 650, 150) 'dim a box around printout


#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
Me.Button1.Location = New System.Drawing.Point(232, 72)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(56, 48)
Me.Button1.TabIndex = 2
Me.Button1.Text = "Print Canned Text"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(312, 158)
Me.Controls.Add(Me.Button1)
Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Name = "Form1"
Me.Text = "Print Tabbed Text"
Me.ResumeLayout(False)
End Sub
#End Region


'we have a "PRINT" button on form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
mystringformat.SetTabStops(0, mytabs)
'add my scale, to see if tabs line up with columns
myText = myText & "00000000011111111112222222222333333333344444444445" _
& ControlChars.CrLf
myText = myText & "12345678901234567890123456789012345678901234567890" _
& ControlChars.CrLf
'we might tune the values in mytabs to get perfect vertical alignment
'the relationship between the scale and columns changes with other fonts
'in any case, mytabs will line up the columns of report data,
'and the character spacing (with Lucida) is uniform within each tab area
myText = myText & "NAME" & ControlChars.Tab & _
"NUMBER" & ControlChars.Tab & _
"START DATE" & ControlChars.Tab & _
"TITLE" & ControlChars.CrLf
myText = myText & "Jim" & ControlChars.Tab & _
"14457" & ControlChars.Tab & _
"08-02-1995" & ControlChars.Tab & _
"DataBase Administrator" & ControlChars.CrLf
myText = myText & "Betsy" & ControlChars.Tab & _
"16640" & ControlChars.Tab & _
"10-12-1998" & ControlChars.Tab & _
"Programmer Analyst" & ControlChars.CrLf
myText = myText & "Andy" & ControlChars.Tab & _
"17302" & ControlChars.Tab & _
"10-07-2000" & ControlChars.Tab & _
"NetWork Specialist" & ControlChars.CrLf
'print using error handler
Try
Dim printdoc As New PrintDocument
AddHandler printdoc.PrintPage, AddressOf Me.PrintText
printdoc.Print()
Catch ex As Exception
MessageBox.Show("Sorry - - printer problem ? ", ex.ToString)
End Try
End Sub
'sub to print text, invoked by "Print" button on form1
Sub PrintText(ByVal sender As Object, _
ByVal ev As PrintPageEventArgs)
'use drawstring to create text in a graphics object
ev.Graphics.DrawString(myText, myfont, mysolidBrush, _
RectangleF.op_Implicit(myRect), mystringformat)
'specify this is last(or only) page to print
ev.HasMorePages = False
Dim pen As Pen = Pens.Black
ev.Graphics.DrawRectangle(pen, myRect) 'draw box around printout
End Sub
'
End Class
 
Back
Top