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