Imports System.Drawing.Printing
Public Class
.
.
.
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim PrintFont, HeaderFont, PrintFont_A, PrintFont_B, PrintFont_C As Font
Dim Height_H, Width_H As Single '每行高度,宽度
Dim HeaderLeft, HeaderTop As Single
‘字体设置
PrintFont = New Font("仿宋_GB2312", 11, FontStyle.Regular)
PrintFont_A = New Font("仿宋_GB2312", 11, FontStyle.Bold)
PrintFont_B = New Font("仿宋_GB2312", 13, FontStyle.Regular)
PrintFont_C = New Font("仿宋_GB2312", 11, FontStyle.Regular)
HeaderFont = New Font("仿宋_GB2312", 22, FontStyle.Bold)
’现在就可以对你的表格进行设置了!
e.Graphics.DrawString("日报表", HeaderFont, Brushes.Black, 360, 40, New StringFormat())
e.Graphics.DrawString("单位:", PrintFont_B, Brushes.Black, 15, 40, New StringFormat())
e.Graphics.DrawString("值班:", PrintFont_B, Brushes.Black, 400, 50, New StringFormat())
e.Graphics.DrawString("填表日期:_________", PrintFont_B, Brushes.Black, 805, 50, New StringFormat())
.
.
.
END SUB
.
.
.
END CLASS
Const GENERIC_READ = &H80000000
Const GENERIC_WRITE = &H40000000
Const OPEN_EXISTING = 3
Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
(ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, ByVal lpSecurityAttributes As Integer, ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer) As IntPtr
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim iHandle As IntPtr
iHandle = CreateFile("LPT1", GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0)
If (iHandle.ToInt32 = -1) Then
MsgBox("没有连接打印机或者打印机端口不是LPT1")
Exit Sub
Else
If i = 0 Then MsgBox("打印机连接成功!")
Dim fs As New FileStream(iHandle, FileAccess.ReadWrite)
Dim sr As New StreamReader(fs) '读数据
Dim sw As New StreamWriter(fs, System.Text.Encoding.Default) '写数据