这是前两年做的一个打形码打印的小程序,用户的要求很简单,打孔纸,1600KIII的打印机,定位连续打印 一个号段内的所有号码的条形码,每张纸打一个号。刚开始,由于每张纸的高度只有9CM,走纸总有问题,后来查了资料才知道,1600KIII走纸的最小纸张高度是10点几公分,(具体多少忘了,时间太长了),没办法,只有连续先打单号,再返回来,连续打双号。
花了一周的时间调试打印机的定位,后来很好用。贴出来,给做定位打印和条形码打印的朋友做个参考吧。(呵呵 现在好好不用VB语言写程序了)
Imports Microsoft.VisualBasic
Imports System.Math
Imports System.Drawing.Printing
Imports System.Runtime.InteropServices
Public Class FrmPrintMain
Inherits System.Windows.Forms.Form
Private StrCurrentNum As String
Private StrStartNo, StrEndNo As String '打印的起始和终止号码
Private ispre As Integer
Private StrFont As String
Dim g As Graphics
Private intSetLeft, intSetTop As Integer '设置的左边距和上边距
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
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
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents PrintDocument1 As System.Drawing.Printing.PrintDocument
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Label7 As System.Windows.Forms.Label
Friend WithEvents TextBox6 As System.Windows.Forms.TextBox
Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents TextBox7 As System.Windows.Forms.TextBox
Friend WithEvents Label8 As System.Windows.Forms.Label
Friend WithEvents Label9 As System.Windows.Forms.Label
Friend WithEvents Label10 As System.Windows.Forms.Label
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents PrintPreviewDialog1 As System.Windows.Forms.PrintPreviewDialog
Friend WithEvents FontDialog1 As System.Windows.Forms.FontDialog
Friend WithEvents Label11 As System.Windows.Forms.Label
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents btnFontSet As System.Windows.Forms.Button
Friend WithEvents btnHelp As System.Windows.Forms.Button
Friend WithEvents btnClose As System.Windows.Forms.Button
Friend WithEvents btnPrint As System.Windows.Forms.Button
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label12 As System.Windows.Forms.Label
Friend WithEvents Label13 As System.Windows.Forms.Label
Friend WithEvents Label14 As System.Windows.Forms.Label
Friend WithEvents Label15 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents TextBox8 As System.Windows.Forms.TextBox
Friend WithEvents NumericUpDown1 As System.Windows.Forms.NumericUpDown
Friend WithEvents NumericUpDown2 As System.Windows.Forms.NumericUpDown
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents TextBox9 As System.Windows.Forms.TextBox
Friend WithEvents Label16 As System.Windows.Forms.Label
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FrmPrintMain))
Me.PrintDocument1 = New System.Drawing.Printing.PrintDocument
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.TextBox8 = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.Label11 = New System.Windows.Forms.Label
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.Label10 = New System.Windows.Forms.Label
Me.Label9 = New System.Windows.Forms.Label
Me.Label8 = New System.Windows.Forms.Label
Me.TextBox7 = New System.Windows.Forms.TextBox
Me.Label7 = New System.Windows.Forms.Label
Me.TextBox6 = New System.Windows.Forms.TextBox
Me.TextBox5 = New System.Windows.Forms.TextBox
Me.TextBox4 = New System.Windows.Forms.TextBox
Me.Label6 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.PrintPreviewDialog1 = New System.Windows.Forms.PrintPreviewDialog
Me.FontDialog1 = New System.Windows.Forms.FontDialog
Me.Panel1 = New System.Windows.Forms.Panel
Me.Button1 = New System.Windows.Forms.Button
Me.btnFontSet = New System.Windows.Forms.Button
Me.btnHelp = New System.Windows.Forms.Button
Me.btnClose = New System.Windows.Forms.Button
Me.btnPrint = New System.Windows.Forms.Button
Me.GroupBox2 = New System.Windows.Forms.GroupBox
Me.TextBox9 = New System.Windows.Forms.TextBox
Me.Label4 = New System.Windows.Forms.Label
Me.NumericUpDown2 = New System.Windows.Forms.NumericUpDown
Me.NumericUpDown1 = New System.Windows.Forms.NumericUpDown
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Label12 = New System.Windows.Forms.Label
Me.Label13 = New System.Windows.Forms.Label
Me.Label14 = New System.Windows.Forms.Label
Me.Label15 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Label16 = New System.Windows.Forms.Label
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.GroupBox1.SuspendLayout()
Me.Panel1.SuspendLayout()
Me.GroupBox2.SuspendLayout()
CType(Me.NumericUpDown2, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.NumericUpDown1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'PrintDocument1
'
'
'GroupBox1
'
Me.GroupBox1.BackColor = System.Drawing.SystemColors.Control
Me.GroupBox1.Controls.Add(Me.TextBox8)
Me.GroupBox1.Controls.Add(Me.Label3)
Me.GroupBox1.Controls.Add(Me.Label11)
Me.GroupBox1.Controls.Add(Me.TextBox3)
Me.GroupBox1.Controls.Add(Me.Label10)
Me.GroupBox1.Controls.Add(Me.Label9)
Me.GroupBox1.Controls.Add(Me.Label8)
Me.GroupBox1.Controls.Add(Me.TextBox7)
Me.GroupBox1.Controls.Add(Me.Label7)
Me.GroupBox1.Controls.Add(Me.TextBox6)
Me.GroupBox1.Controls.Add(Me.TextBox5)
Me.GroupBox1.Controls.Add(Me.TextBox4)
Me.GroupBox1.Controls.Add(Me.Label6)
Me.GroupBox1.Controls.Add(Me.Label5)
Me.GroupBox1.Dock = System.Windows.Forms.DockStyle.Top
Me.GroupBox1.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.GroupBox1.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.GroupBox1.Location = New System.Drawing.Point(0, 0)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(690, 144)
Me.GroupBox1.TabIndex = 27
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "当前打印机及纸张信息"
'
'TextBox8
'
Me.TextBox8.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(255, Byte), CType(192, Byte))
Me.TextBox8.Location = New System.Drawing.Point(504, 32)
Me.TextBox8.Name = "TextBox8"
Me.TextBox8.Size = New System.Drawing.Size(88, 23)
Me.TextBox8.TabIndex = 42
Me.TextBox8.TabStop = False
Me.TextBox8.Text = "TextBox8"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(384, 32)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(112, 23)
Me.Label3.TabIndex = 41
Me.Label3.Text = "打印机分辨率:"
'
'Label11
'
Me.Label11.Location = New System.Drawing.Point(40, 96)
Me.Label11.Name = "Label11"
Me.Label11.Size = New System.Drawing.Size(88, 23)
Me.Label11.TabIndex = 40
Me.Label11.Text = "打印字体:"
'
'TextBox3
'
Me.TextBox3.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(255, Byte), CType(192, Byte))
Me.TextBox3.Location = New System.Drawing.Point(152, 96)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.ReadOnly = True
Me.TextBox3.Size = New System.Drawing.Size(88, 23)
Me.TextBox3.TabIndex = 38
Me.TextBox3.TabStop = False
Me.TextBox3.Text = "宋体"
'
'Label10
'
Me.Label10.Location = New System.Drawing.Point(600, 104)
Me.Label10.Name = "Label10"
Me.Label10.Size = New System.Drawing.Size(64, 23)
Me.Label10.TabIndex = 37
Me.Label10.Text = "(毫米)"
'
'Label9
'
Me.Label9.Location = New System.Drawing.Point(600, 64)
Me.Label9.Name = "Label9"
Me.Label9.Size = New System.Drawing.Size(64, 23)
Me.Label9.TabIndex = 36
Me.Label9.Text = "(毫米)"
'
'Label8
'
Me.Label8.Location = New System.Drawing.Point(40, 32)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(104, 23)
Me.Label8.TabIndex = 34
Me.Label8.Text = "打印机名称:"
'
'TextBox7
'
Me.TextBox7.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(255, Byte), CType(192, Byte))
Me.TextBox7.Location = New System.Drawing.Point(152, 32)
Me.TextBox7.Name = "TextBox7"
Me.TextBox7.ReadOnly = True
Me.TextBox7.Size = New System.Drawing.Size(216, 23)
Me.TextBox7.TabIndex = 33
Me.TextBox7.TabStop = False
Me.TextBox7.Text = "TextBox7"
'
'Label7
'
Me.Label7.Location = New System.Drawing.Point(40, 64)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(112, 23)
Me.Label7.TabIndex = 32
Me.Label7.Text = "纸张类型:"
'
'TextBox6
'
Me.TextBox6.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(255, Byte), CType(192, Byte))
Me.TextBox6.Location = New System.Drawing.Point(152, 64)
Me.TextBox6.Name = "TextBox6"
Me.TextBox6.Size = New System.Drawing.Size(88, 23)
Me.TextBox6.TabIndex = 31
Me.TextBox6.TabStop = False
Me.TextBox6.Text = "TextBox6"
'
'TextBox5
'
Me.TextBox5.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(255, Byte), CType(192, Byte))
Me.TextBox5.Location = New System.Drawing.Point(504, 96)
Me.TextBox5.Name = "TextBox5"
Me.TextBox5.ReadOnly = True
Me.TextBox5.Size = New System.Drawing.Size(88, 23)
Me.TextBox5.TabIndex = 30
Me.TextBox5.TabStop = False
Me.TextBox5.Text = "210"
'
'TextBox4
'
Me.TextBox4.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(255, Byte), CType(192, Byte))
Me.TextBox4.Location = New System.Drawing.Point(504, 64)
Me.TextBox4.Name = "TextBox4"
Me.TextBox4.ReadOnly = True
Me.TextBox4.Size = New System.Drawing.Size(88, 23)
Me.TextBox4.TabIndex = 29
Me.TextBox4.TabStop = False
Me.TextBox4.Text = "149"
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(384, 96)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(104, 23)
Me.Label6.TabIndex = 28
Me.Label6.Text = "纸张高度:"
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(384, 64)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(104, 23)
Me.Label5.TabIndex = 27
Me.Label5.Text = "纸张宽度:"
'
'PrintPreviewDialog1
'
Me.PrintPreviewDialog1.AutoScrollMargin = New System.Drawing.Size(0, 0)
Me.PrintPreviewDialog1.AutoScrollMinSize = New System.Drawing.Size(0, 0)
Me.PrintPreviewDialog1.ClientSize = New System.Drawing.Size(400, 300)
Me.PrintPreviewDialog1.Enabled = True
Me.PrintPreviewDialog1.Icon = CType(resources.GetObject("PrintPreviewDialog1.Icon"), System.Drawing.Icon)
Me.PrintPreviewDialog1.Location = New System.Drawing.Point(150, 21)
Me.PrintPreviewDialog1.MinimumSize = New System.Drawing.Size(375, 250)
Me.PrintPreviewDialog1.Name = "PrintPreviewDialog1"
Me.PrintPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty
Me.PrintPreviewDialog1.Visible = False
'
'Panel1
'
Me.Panel1.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
Me.Panel1.Controls.Add(Me.Button1)
Me.Panel1.Controls.Add(Me.btnFontSet)
Me.Panel1.Controls.Add(Me.btnHelp)
Me.Panel1.Controls.Add(Me.btnClose)
Me.Panel1.Controls.Add(Me.btnPrint)
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Bottom
Me.Panel1.Location = New System.Drawing.Point(0, 316)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(690, 100)
Me.Panel1.TabIndex = 44
'
'Button1
'
Me.Button1.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(255, Byte), CType(192, Byte))
Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.Button1.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button1.Location = New System.Drawing.Point(168, 40)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(80, 28)
Me.Button1.TabIndex = 6
Me.Button1.Text = "打印预览"
'
'btnFontSet
'
Me.btnFontSet.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(255, Byte), CType(192, Byte))
Me.btnFontSet.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btnFontSet.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.btnFontSet.Location = New System.Drawing.Point(72, 40)
Me.btnFontSet.Name = "btnFontSet"
Me.btnFontSet.Size = New System.Drawing.Size(80, 28)
Me.btnFontSet.TabIndex = 5
Me.btnFontSet.Text = "字体设置"
'
'btnHelp
'
Me.btnHelp.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(255, Byte), CType(192, Byte))
Me.btnHelp.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btnHelp.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.btnHelp.Location = New System.Drawing.Point(360, 40)
Me.btnHelp.Name = "btnHelp"
Me.btnHelp.Size = New System.Drawing.Size(80, 28)
Me.btnHelp.TabIndex = 8
Me.btnHelp.Text = "使用帮助"
'
'btnClose
'
Me.btnClose.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(255, Byte), CType(192, Byte))
Me.btnClose.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btnClose.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.btnClose.Location = New System.Drawing.Point(456, 40)
Me.btnClose.Name = "btnClose"
Me.btnClose.Size = New System.Drawing.Size(80, 28)
Me.btnClose.TabIndex = 9
Me.btnClose.Text = "关 闭"
'
'btnPrint
'
Me.btnPrint.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(255, Byte), CType(192, Byte))
Me.btnPrint.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btnPrint.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.btnPrint.Location = New System.Drawing.Point(264, 40)
Me.btnPrint.Name = "btnPrint"
Me.btnPrint.Size = New System.Drawing.Size(80, 28)
Me.btnPrint.TabIndex = 7
Me.btnPrint.Text = "打 印"
'
'GroupBox2
'
Me.GroupBox2.BackColor = System.Drawing.SystemColors.Control
Me.GroupBox2.Controls.Add(Me.ComboBox1)
Me.GroupBox2.Controls.Add(Me.Label16)
Me.GroupBox2.Controls.Add(Me.TextBox9)
Me.GroupBox2.Controls.Add(Me.Label4)
Me.GroupBox2.Controls.Add(Me.NumericUpDown2)
Me.GroupBox2.Controls.Add(Me.NumericUpDown1)
Me.GroupBox2.Controls.Add(Me.Label2)
Me.GroupBox2.Controls.Add(Me.Label1)
Me.GroupBox2.Controls.Add(Me.TextBox2)
Me.GroupBox2.Controls.Add(Me.Label12)
Me.GroupBox2.Controls.Add(Me.Label13)
Me.GroupBox2.Controls.Add(Me.Label14)
Me.GroupBox2.Controls.Add(Me.Label15)
Me.GroupBox2.Controls.Add(Me.TextBox1)
Me.GroupBox2.Dock = System.Windows.Forms.DockStyle.Fill
Me.GroupBox2.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.GroupBox2.Location = New System.Drawing.Point(0, 144)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(690, 172)
Me.GroupBox2.TabIndex = 45
Me.GroupBox2.TabStop = False
Me.GroupBox2.Text = "设置打印信息"
'
'TextBox9
'
Me.TextBox9.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(255, Byte), CType(192, Byte))
Me.TextBox9.Location = New System.Drawing.Point(128, 120)
Me.TextBox9.Name = "TextBox9"
Me.TextBox9.ReadOnly = True
Me.TextBox9.Size = New System.Drawing.Size(96, 23)
Me.TextBox9.TabIndex = 63
Me.TextBox9.Text = "1"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(56, 120)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(48, 23)
Me.Label4.TabIndex = 62
Me.Label4.Text = "数量:"
'
'NumericUpDown2
'
Me.NumericUpDown2.Location = New System.Drawing.Point(448, 80)
Me.NumericUpDown2.Maximum = New Decimal(New Integer() {380, 0, 0, 0})
Me.NumericUpDown2.Name = "NumericUpDown2"
Me.NumericUpDown2.Size = New System.Drawing.Size(64, 23)
Me.NumericUpDown2.TabIndex = 61
Me.NumericUpDown2.Value = New Decimal(New Integer() {10, 0, 0, 0})
'
'NumericUpDown1
'
Me.NumericUpDown1.Location = New System.Drawing.Point(448, 32)
Me.NumericUpDown1.Maximum = New Decimal(New Integer() {380, 0, 0, 0})
Me.NumericUpDown1.Name = "NumericUpDown1"
Me.NumericUpDown1.Size = New System.Drawing.Size(64, 23)
Me.NumericUpDown1.TabIndex = 60
Me.NumericUpDown1.Value = New Decimal(New Integer() {10, 0, 0, 0})
'
'Label2
'
Me.Label2.ForeColor = System.Drawing.Color.Red
Me.Label2.Location = New System.Drawing.Point(520, 80)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(56, 23)
Me.Label2.TabIndex = 59
Me.Label2.Text = "(毫米)"
'
'Label1
'
Me.Label1.ForeColor = System.Drawing.Color.Red
Me.Label1.Location = New System.Drawing.Point(520, 32)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(56, 23)
Me.Label1.TabIndex = 58
Me.Label1.Text = "(毫米)"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(128, 80)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.TabIndex = 2
Me.TextBox2.Text = "0000001"
'
'Label12
'
Me.Label12.Location = New System.Drawing.Point(328, 80)
Me.Label12.Name = "Label12"
Me.Label12.Size = New System.Drawing.Size(88, 23)
Me.Label12.TabIndex = 56
Me.Label12.Text = "上 边 距:"
'
'Label13
'
Me.Label13.Location = New System.Drawing.Point(328, 32)
Me.Label13.Name = "Label13"
Me.Label13.Size = New System.Drawing.Size(96, 23)
Me.Label13.TabIndex = 53
Me.Label13.Text = "左 边 距:"
'
'Label14
'
Me.Label14.Location = New System.Drawing.Point(56, 80)
Me.Label14.Name = "Label14"
Me.Label14.Size = New System.Drawing.Size(56, 23)
Me.Label14.TabIndex = 52
Me.Label14.Text = "终止号"
'
'Label15
'
Me.Label15.Location = New System.Drawing.Point(56, 32)
Me.Label15.Name = "Label15"
Me.Label15.Size = New System.Drawing.Size(56, 23)
Me.Label15.TabIndex = 51
Me.Label15.Text = "起始号"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(128, 32)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "0000001"
'
'Label16
'
Me.Label16.Location = New System.Drawing.Point(328, 120)
Me.Label16.Name = "Label16"
Me.Label16.TabIndex = 64
Me.Label16.Text = "打印方法:"
'
'ComboBox1
'
Me.ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboBox1.Items.AddRange(New Object() {"顺序打印", "打印单号", "打印双号"})
Me.ComboBox1.Location = New System.Drawing.Point(448, 120)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(104, 22)
Me.ComboBox1.TabIndex = 65
'
'FrmPrintMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.BackColor = System.Drawing.SystemColors.Control
Me.ClientSize = New System.Drawing.Size(690, 416)
Me.Controls.Add(Me.GroupBox2)
Me.Controls.Add(Me.Panel1)
Me.Controls.Add(Me.GroupBox1)
Me.ForeColor = System.Drawing.Color.Black
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "FrmPrintMain"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "条形码打印"
Me.GroupBox1.ResumeLayout(False)
Me.Panel1.ResumeLayout(False)
Me.GroupBox2.ResumeLayout(False)
CType(Me.NumericUpDown2, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.NumericUpDown1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub FrmPrintMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ispre = 1 '表示是打印预览
StrFont = "宋体"
Me.TextBox3.Text = StrFont
SetPaperType() '设置默认的纸张为“zdrpaper”
'取得默认纸张的大小
Me.TextBox7.Text = Me.PrintDocument1.PrinterSettings.DefaultPageSettings.PrinterSettings.PrinterName '打印机名称
Dim aaa As String
aaa = Me.PrintDocument1.PrinterSettings.DefaultPageSettings.PaperSize.PaperName
Me.TextBox6.Text = Me.PrintDocument1.PrinterSettings.DefaultPageSettings.PaperSize.PaperName '打印纸名称
Me.TextBox4.Text = CInt(Me.PrintDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Width * 0.254) '打印纸宽
Me.TextBox5.Text = CInt(Me.PrintDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Height * 0.254) '打印纸高
Me.TextBox1.Focus()
Me.ComboBox1.SelectedIndex = 0
End Sub
'在打印机的分辨率是180X180时使用
Public Sub CODE39_180X180( _
ByVal strBarCode As String, _
ByVal PrintObject As Graphics, _
Optional ByVal intXPos As Single = 0, _
Optional ByVal intYPos As Single = 0, _
Optional ByVal intPrintHeight As Single = 16, _
Optional ByVal bolPrintText As Boolean = True _
)
' 参数说明:
' strBarCode - 要打印的条形码字符串
' intXPos, intYPos - 打印条形码的左上角坐标(缺省为(0,0),坐标刻度为:毫米)
' intHeight - 打印高度(缺省为一厘米,坐标刻度为:毫米)
' bolPrintText - 是否打印人工识别字符(缺省为true)
If strBarCode = "" Then MessageBox.Show("无打印输出信息。", "信息:", MessageBoxButtons.OK, MessageBoxIcon.Information) : Exit Sub ' 不打印空串
Static strBarTable(39) As String, intIndex As Integer ' 当前处理的字符串索引
Dim I As Integer, J As Integer, K As Integer ' 循环控制变量
Dim X, Y As Integer, strBC As String
Dim XFont As Font = New Font(Me.TextBox3.Text, 10)
Dim intHeight As Single = 0
Dim XPen As Pen = New Pen(Color.Black)
XPen.Width = 1
Dim GrUnit As GraphicsUnit = PrintObject.PageUnit '保存度量单位
Dim intWidthCU As Integer ' 粗线和宽间隙宽度
Dim intWidthXI As Integer = Int(0.1763891 * PrintObject.DpiX / 25.4) ' 细线和窄间隙宽度
intWidthCU = intWidthXI * 3
PrintObject.PageUnit = GraphicsUnit.Pixel
PrintObject.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
PrintObject.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit
X = intXPos : Y = intYPos : strBC = ""
X = X * PrintObject.DpiX / 25.4
Y = Y * PrintObject.DpiY / 25.4
intPrintHeight = CInt(intPrintHeight * PrintObject.DpiY / 25.4)
' 初始化条码编码格式表"0"-"9","A-Z","-","%","$"和"*" 的条码编码格式,总共 40 个字符
strBarTable(0) = "001100100" ' 0
strBarTable(1) = "100010100" ' 1
strBarTable(2) = "010010100" ' 2
strBarTable(3) = "110000100" ' 3
strBarTable(4) = "001010100" ' 4
strBarTable(5) = "101000100" ' 5
strBarTable(6) = "011000100" ' 6
strBarTable(7) = "000110100" ' 7
strBarTable(8) = "100100100" ' 8
strBarTable(9) = "010100100" ' 9
strBarTable(10) = "100010010" ' A
strBarTable(11) = "010010010" ' B
strBarTable(12) = "110000010" ' C
strBarTable(13) = "001010010" ' D
strBarTable(14) = "101000010" ' E
strBarTable(15) = "011000010" ' F
strBarTable(16) = "000110010" ' G
strBarTable(17) = "100100010" ' H
strBarTable(18) = "010100010" ' I
strBarTable(19) = "001100010" ' J
strBarTable(20) = "100010001" ' K
strBarTable(21) = "010010001" ' L
strBarTable(22) = "110000001" ' M
strBarTable(23) = "001010001" ' N
strBarTable(24) = "101000001" ' O
strBarTable(25) = "011000001" ' P
strBarTable(26) = "000110001" ' Q
strBarTable(27) = "100100001" ' R
strBarTable(28) = "010100001" ' S
strBarTable(29) = "001100001" ' T
strBarTable(30) = "100011000" ' U
strBarTable(31) = "010011000" ' V
strBarTable(32) = "110001000" ' W
strBarTable(33) = "001011000" ' X
strBarTable(34) = "101001000" ' Y
strBarTable(35) = "011001000" ' Z
strBarTable(36) = "000111000" ' -
strBarTable(37) = "100101000" ' %
strBarTable(38) = "010101000" ' $
strBarTable(39) = "001101000" ' *
'
strBC = strBarCode.ToUpper
If bolPrintText = True Then
intHeight = 67 ' CInt(intPrintHeight - PrintObject.MeasureString(strBC, XFont).Height) '测量打印文本的高度
End If
' 添加起始字符
If Microsoft.VisualBasic.Left(strBC, 1) <> "*" Then
strBC = "*" & strBC
End If
' 添加结束字符
If Microsoft.VisualBasic.Right(strBC, 1) <> "*" Then
strBC = strBC & "*"
End If
' 循环处理每个要显示的条码字符
For I = 1 To strBC.Length
' 确定当前字符在 strBarTable 中的索引
Select Case strBC.Substring(I - 1, 1)
Case "*"
intIndex = 39
Case "$"
intIndex = 38
Case "%"
intIndex = 37
Case "-"
intIndex = 36
Case "0" To "9"
intIndex = CInt(strBC.Substring(I - 1, 1))
Case "A" To "Z"
intIndex = Asc(strBC.Substring(I - 1, 1)) - Asc("A") + 10
Case Else
MessageBox.Show("要打印的条形码字符串中包含无效字符!" + vbCrLf + "当前版本只支持字符 '0'-'9','A'-'Z','-','%','$'和'*'", "信息:", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End Select
'左 上边距为50时修正如下
'intSetLeft = CInt(Me.NumericUpDown1.Value + 60 / 0.254)
'intSetTop = CInt(Me.NumericUpDown2.Value + 52 / 0.254)
intSetLeft = CInt(Me.NumericUpDown1.Value * 7.1)
intSetTop = CInt(Me.NumericUpDown2.Value * 7.1)
intSetTop = intSetTop - 100
If bolPrintText = True Then
'是否在条形码下方打印人工识别字符
PrintObject.DrawString(strBC.Substring(I - 1, 1), XFont, New SolidBrush(Color.Black), X - 71 + intSetLeft, Y + intHeight + 8 + intSetTop)
End If
For J = 1 To 5
If strBarTable(intIndex).Substring(J - 1, 1) = "0" Then
' 画细线
For K = 1 To intWidthXI
PrintObject.DrawLine(XPen, X + K - 71 + intSetLeft, 71 + intSetTop, X + K - 71 + intSetLeft, 141 + intSetTop) '75为1CM
Next
X = X + intWidthXI
Else
' 画宽线
For K = 1 To intWidthCU
PrintObject.DrawLine(XPen, X + K - 71 + intSetLeft, 71 + intSetTop, X + K - 71 + intSetLeft, 141 + intSetTop)
Next
X = X + intWidthCU
End If
' 每个字符条码之间为窄间隙
If J = 5 Then
X = X + intWidthXI * 3 - 1
Exit For
End If
If strBarTable(intIndex).Substring(J + 4, 1) = "0" Then
'窄间隙
X = X + intWidthXI * 3 - 1
Else
'宽间隙
X = X + intWidthCU * 2 - 1
End If
Next J
Next I
XPen.Dispose()
PrintObject.PageUnit = GrUnit
End Sub
'在打印机的分辨率是360X180时使用
Public Sub CODE39_360X180( _
ByVal strBarCode As String, _
ByVal PrintObject As Graphics, _
Optional ByVal intXPos As Single = 0, _
Optional ByVal intYPos As Single = 0, _
Optional ByVal intPrintHeight As Single = 16, _
Optional ByVal bolPrintText As Boolean = True _
)
' 参数说明:
' strBarCode - 要打印的条形码字符串
' intXPos, intYPos - 打印条形码的左上角坐标(缺省为(0,0),坐标刻度为:毫米)
' intHeight - 打印高度(缺省为一厘米,坐标刻度为:毫米)
' bolPrintText - 是否打印人工识别字符(缺省为true)
If strBarCode = "" Then MessageBox.Show("无打印输出信息!!!", "条形码打印", MessageBoxButtons.OK, MessageBoxIcon.Information) : Exit Sub ' 不打印空串
Static strBarTable(39) As String, intIndex As Integer ' 当前处理的字符串索引
Dim I As Integer, J As Integer, K As Integer ' 循环控制变量
Dim X, Y As Integer, strBC As String
Dim XFont As Font = New Font(Me.TextBox3.Text, 5)
Dim intHeight As Single = 0
Dim XPen As Pen = New Pen(Color.Black)
XPen.Width = 1
Dim GrUnit As GraphicsUnit = PrintObject.PageUnit '保存度量单位
Dim intWidthCU As Integer ' 粗线和宽间隙宽度
Dim intWidthXI As Integer = Int(0.1763891 * PrintObject.DpiX / 25.4) ' 细线和窄间隙宽度
intWidthCU = intWidthXI * 2.5
PrintObject.PageUnit = GraphicsUnit.Pixel
PrintObject.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
PrintObject.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit
X = intXPos : Y = intYPos : strBC = ""
X = X * PrintObject.DpiX / 25.4
Y = Y * PrintObject.DpiY / 25.4
intPrintHeight = CInt(intPrintHeight * PrintObject.DpiY / 25.4)
' 初始化条码编码格式表"0"-"9","A-Z","-","%","$"和"*" 的条码编码格式,总共 40 个字符
strBarTable(0) = "001100100" ' 0
strBarTable(1) = "100010100" ' 1
strBarTable(2) = "010010100" ' 2
strBarTable(3) = "110000100" ' 3
strBarTable(4) = "001010100" ' 4
strBarTable(5) = "101000100" ' 5
strBarTable(6) = "011000100" ' 6
strBarTable(7) = "000110100" ' 7
strBarTable(8) = "100100100" ' 8
strBarTable(9) = "010100100" ' 9
strBarTable(10) = "100010010" ' A
strBarTable(11) = "010010010" ' B
strBarTable(12) = "110000010" ' C
strBarTable(13) = "001010010" ' D
strBarTable(14) = "101000010" ' E
strBarTable(15) = "011000010" ' F
strBarTable(16) = "000110010" ' G
strBarTable(17) = "100100010" ' H
strBarTable(18) = "010100010" ' I
strBarTable(19) = "001100010" ' J
strBarTable(20) = "100010001" ' K
strBarTable(21) = "010010001" ' L
strBarTable(22) = "110000001" ' M
strBarTable(23) = "001010001" ' N
strBarTable(24) = "101000001" ' O
strBarTable(25) = "011000001" ' P
strBarTable(26) = "000110001" ' Q
strBarTable(27) = "100100001" ' R
strBarTable(28) = "010100001" ' S
strBarTable(29) = "001100001" ' T
strBarTable(30) = "100011000" ' U
strBarTable(31) = "010011000" ' V
strBarTable(32) = "110001000" ' W
strBarTable(33) = "001011000" ' X
strBarTable(34) = "101001000" ' Y
strBarTable(35) = "011001000" ' Z
strBarTable(36) = "000111000" ' -
strBarTable(37) = "100101000" ' %
strBarTable(38) = "010101000" ' $
strBarTable(39) = "001101000" ' *
'
strBC = strBarCode.ToUpper
If bolPrintText = True Then
intHeight = 67 ' CInt(intPrintHeight - PrintObject.MeasureString(strBC, XFont).Height) '测量打印文本的高度
End If
' 添加起始字符
If Microsoft.VisualBasic.Left(strBC, 1) <> "*" Then
strBC = "*" & strBC
End If
' 添加结束字符
If Microsoft.VisualBasic.Right(strBC, 1) <> "*" Then
strBC = strBC & "*"
End If
' 循环处理每个要显示的条码字符
For I = 1 To strBC.Length
' 确定当前字符在 strBarTable 中的索引
Select Case strBC.Substring(I - 1, 1)
Case "*"
intIndex = 39
Case "$"
intIndex = 38
Case "%"
intIndex = 37
Case "-"
intIndex = 36
Case "0" To "9"
intIndex = CInt(strBC.Substring(I - 1, 1))
Case "A" To "Z"
intIndex = Asc(strBC.Substring(I - 1, 1)) - Asc("A") + 10
Case Else
MessageBox.Show("要打印的条形码字符串中包含无效字符!" + vbCrLf + "当前版本只支持字符 '0'-'9','A'-'Z','-','%','$'和'*'", "信息:", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End Select
intSetLeft = CInt(Me.NumericUpDown1.Value * 14.2)
intSetTop = CInt(Me.NumericUpDown2.Value * 7.09)
intSetTop = intSetTop - 100
If bolPrintText = True Then
'是否在条形码下方打印人工识别字符
PrintObject.DrawString(strBC.Substring(I - 1, 1), XFont, New SolidBrush(Color.Black), X - 1 - 142 + intSetLeft, Y + intHeight + 9 + intSetTop)
End If
For J = 1 To 5
If strBarTable(intIndex).Substring(J - 1, 1) = "0" Then
' 画细线
For K = 1 To intWidthXI
PrintObject.DrawLine(XPen, X + K + intSetLeft - 142, Y + intSetTop, X + K + intSetLeft - 142, Y + intHeight + 8 + intSetTop)
Next
X = X + intWidthXI
Else
' 画宽线
For K = 1 To intWidthCU
PrintObject.DrawLine(XPen, X + K + intSetLeft - 142, Y + intSetTop, X + K + intSetLeft - 142, Y + intHeight + 8 + intSetTop)
Next
X = X + intWidthCU
End If
' 每个字符条码之间为窄间隙
If J = 5 Then
X = X + intWidthXI * 3 - 1
Exit For
End If
If strBarTable(intIndex).Substring(J + 4, 1) = "0" Then
'窄间隙
X = X + intWidthXI * 3 - 1
Else
'宽间隙
X = X + intWidthCU * 2 - 1
End If
Next J
Next I
XPen.Dispose()
PrintObject.PageUnit = GrUnit
End Sub
'打印机设置 按钮
Private Sub btnPriterSetUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim printDialog As New PrintDialog
printDialog.Document = Me.PrintDocument1
' lineReader = new StringReader(textBox.Text);
If printDialog.ShowDialog() = DialogResult.OK Then
Try
PrintDocument1.Print()
Catch ex As Exception
MessageBox.Show(ex.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error)
PrintDocument1.PrintController.OnEndPrint(PrintDocument1, New System.Drawing.Printing.PrintEventArgs)
End Try
End If
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
' Me.TextBox3.Text = "打印机的分辨率为:" + e.PageSettings.PrinterResolution.X.ToString() + "*" + e.PageSettings.PrinterResolution.X.ToString()
Dim MyLeftMargin As Single = e.MarginBounds.Left '纸张的左边距
Dim MyTopMargin As Single = e.MarginBounds.Top '纸张的上边距 10MM对应的结果是39 20MM对应的结果是79,是如何计算出来的??
'计算方法:10/0.254=39.37(实际上是将MM转换为百分之一英寸) 即1mm=3.937(百分之一英寸)=1/0.254(百分之一英寸)
' Me.TextBox3.Text += ",纸张左边距=" + MyLeftMargin.ToString() + ",纸张上边距=" + MyTopMargin.ToString()
'好像和打印的分辨率没有关系???
Dim MyMod As Integer
MyMod = CInt(StrCurrentNum) Mod 2 '取余数
Dim Isprint As Integer
Isprint = 0 '是否打印了
If Me.ComboBox1.Text = "顺序打印" Then
If Me.TextBox8.Text.ToLower = "180x180" Then
Call CODE39_180X180(StrCurrentNum, e.Graphics, 10, 10, 13)
Isprint = 1
Else
Call CODE39_360X180(StrCurrentNum, e.Graphics, 10, 10, 13)
Isprint = 1
End If
ElseIf Me.ComboBox1.Text = "打印单号" Then
If Me.TextBox8.Text.ToLower = "180x180" And MyMod = 1 Then
Call CODE39_180X180(StrCurrentNum, e.Graphics, 10, 10, 13)
ElseIf Me.TextBox8.Text.ToLower <> "180x180" And MyMod = 1 Then
Call CODE39_360X180(StrCurrentNum, e.Graphics, 10, 10, 13)
End If
ElseIf Me.ComboBox1.Text = "打印双号" Then
If Me.TextBox8.Text.ToLower = "180x180" And MyMod = 0 Then
Call CODE39_180X180(StrCurrentNum, e.Graphics, 10, 10, 13)
ElseIf Me.TextBox8.Text.ToLower <> "180x180" And MyMod = 0 Then
Call CODE39_360X180(StrCurrentNum, e.Graphics, 10, 10, 13)
End If
End If
Dim S As Integer
Dim MaxS As Integer
MaxS = CInt(Me.TextBox2.Text)
S = CInt(StrCurrentNum)
MaxS = CInt(StrEndNo)
If ispre = 0 And Me.ComboBox1.Text = "顺序打印" Then
S += 1
ElseIf ispre = 0 And Me.ComboBox1.Text <> "顺序打印" Then
S += 2
End If
If S <= MaxS And ispre = 0 Then 'ispre判断是否在预览状态还是打印状态
e.HasMorePages = True '换页(True时有换页动作) HasMorePages属性:是否还有页要打印
Else
e.HasMorePages = False '换页(True 时有换页动作)
End If
'要处理前面是0的数字
StrCurrentNum = CStr(S)
Dim i As Integer
i = StrCurrentNum.Length
Dim j As Integer
For j = 1 To 7 - i
StrCurrentNum = "0" + StrCurrentNum
Next
End Sub
'设置纸张为zdrpaper的纸张
Private Sub SetPaperType()
Dim ps As New PageSettings
Dim i, j As Integer
i = Me.PrintDocument1.PrinterSettings.PaperSizes.Count
For j = 0 To i - 1
Dim StrPaperType As String
StrPaperType = Me.PrintDocument1.PrinterSettings.PaperSizes(j).PaperName.ToString()
If StrPaperType.ToLower = "zdrpaper" Or StrPaperType.ToLower = "custom" Then 'zdrpaper是纸张类型
Me.PrintDocument1.PrinterSettings.DefaultPageSettings.PaperSize = Me.PrintDocument1.PrinterSettings.PaperSizes(j)
End If
Try
Catch ex As Exception
End Try
Console.WriteLine(StrPaperType.ToString())
Next
Me.TextBox8.Text = ps.PrinterResolution.X.ToString() + "X" + ps.PrinterResolution.Y.ToString() '获取打印机分辨率
' Me.TextBox9.Text = ps.PrinterSettings.PaperSizes.
End Sub
' Declare Auto Function ExtractIcon Lib "Shell32.dll" (ByVal src As System.IntPtr, ByVal strFileName As String, ByVal uiIconIndex As UInt32) As System.IntPtr
' Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Ansi Function ShellExecute Lib "shell32" _
Alias "ShellExecuteA" ( _
ByVal hwnd As IntPtr, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Integer) As Integer
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub btnFontSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFontSet.Click
If Me.FontDialog1.ShowDialog = DialogResult.OK Then
StrFont = Me.FontDialog1.Font.Name.ToString()
Me.TextBox3.Text = StrFont
End If
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
If Me.TextBox1.Text = "" Or Me.TextBox2.Text = "" Then
MessageBox.Show("请输入要打印的起始和终止号码!!!", "条形码打印", MessageBoxButtons.OK)
Return
End If
If Me.TextBox2.Text < Me.TextBox1.Text Then
MessageBox.Show("起始号码大于终止号码,请检查输入是否正确!!!", "条形码打印", MessageBoxButtons.OK)
Return
End If
If Me.TextBox7.Text = "" Then
MessageBox.Show("没有安装打印机!!!", "条形码打印", MessageBoxButtons.OK)
Return
End If
If Me.TextBox6.Text.ToLower <> "zdrpaper" Then
If MessageBox.Show("打印机或者打印纸的设置可能有问题,确认要打印吗?", "条形码打印", MessageBoxButtons.YesNo) = DialogResult.No Then
Return
End If
End If
ispre = 0
Dim ISAA As Integer '判断开始位置是否和打死的类型相对应
ISAA = CInt(Me.TextBox1.Text) Mod 2
Dim IntTemp As Integer
IntTemp = CInt(Me.TextBox1.Text)
If (Me.ComboBox1.Text = "打印单号" And ISAA = 0) Or (Me.ComboBox1.Text = "打印双号" And ISAA = 1) Then
IntTemp += 1
StrCurrentNum = CStr(IntTemp)
Dim i As Integer
i = StrCurrentNum.Length
Dim j As Integer
For j = 1 To 7 - i
StrCurrentNum = "0" + StrCurrentNum
Next
Else
StrCurrentNum = Me.TextBox1.Text
End If
' StrCurrentNum = Me.TextBox1.Text
StrStartNo = Me.TextBox1.Text
StrEndNo = Me.TextBox2.Text
intSetLeft = CInt(Me.NumericUpDown1.Value)
intSetTop = CInt(Me.NumericUpDown2.Value)
Try
Me.PrintDocument1.Print()
Catch ex As Exception
MessageBox.Show("打印时出现错误!!!", "条形码打印", MessageBoxButtons.OK)
End Try
End Sub
Private Sub btnHelp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHelp.Click
'调用默认的程序打开文件
ShellExecute(Me.Handle, "open", "条形码打印帮助.CHM", Nothing, Nothing, 1)
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Close()
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Char.IsControl(e.KeyChar) <> True Then
e.Handled = Not Char.IsDigit(e.KeyChar)
End If
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
If Char.IsControl(e.KeyChar) <> True Then
e.Handled = Not Char.IsDigit(e.KeyChar)
End If
End Sub
'打印预览
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Me.TextBox1.Text = "" Or Me.TextBox2.Text = "" Then
MessageBox.Show("请输入要打印的起始和终止号码!!!", "条形码打印", MessageBoxButtons.OK)
Return
End If
If Me.TextBox2.Text < Me.TextBox1.Text Then
MessageBox.Show("起始号码大于终止号码,请检查输入是否正确!!!", "条形码打印", MessageBoxButtons.OK)
Return
End If
If Me.TextBox7.Text = "" Then
MessageBox.Show("没有安装打印机!!!", "条形码打印", MessageBoxButtons.OK)
Return
End If
If Me.TextBox6.Text.ToLower <> "zdrpaper" Then
If MessageBox.Show("打印机或者打印纸的设置有问题,确认要打印吗?", "条形码打印", MessageBoxButtons.YesNo) = DialogResult.No Then
Return
End If
End If
ispre = 1
Dim ISAA As Integer '判断开始位置是否和打死的类型相对应
ISAA = CInt(Me.TextBox1.Text) Mod 2
Dim IntTemp As Integer
IntTemp = CInt(Me.TextBox1.Text)
If (Me.ComboBox1.Text = "打印单号" And ISAA = 0) Or (Me.ComboBox1.Text = "打印双号" And ISAA = 1) Then
IntTemp += 1
StrCurrentNum = CStr(IntTemp)
Dim i As Integer
i = StrCurrentNum.Length
Dim j As Integer
For j = 1 To 7 - i
StrCurrentNum = "0" + StrCurrentNum
Next
Else
StrCurrentNum = Me.TextBox1.Text
End If
' StrCurrentNum = Me.TextBox1.Text
StrStartNo = Me.TextBox1.Text
StrEndNo = Me.TextBox2.Text
intSetLeft = CInt(Me.NumericUpDown1.Value)
intSetTop = CInt(Me.NumericUpDown2.Value)
Try
Me.PrintPreviewDialog1.Document = Me.PrintDocument1
Me.PrintPreviewDialog1.ShowDialog()
Catch ex As Exception
MessageBox.Show("打印时出现错误!!!", "条形码打印", MessageBoxButtons.OK)
End Try
Return
End Sub
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
End Sub
Private Sub TextBox1_TextChanged1(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Sum()
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
Sum()
End Sub
Private Sub Sum()
If Me.TextBox1.Text <> "" And Me.TextBox2.Text <> "" Then
If Me.TextBox1.Text = "" Or Me.TextBox2.Text = "" Or CInt(Me.TextBox1.Text) > CInt(Me.TextBox2.Text) Then
Me.TextBox9.Text = 0
Else
Me.TextBox9.Text = CInt(Me.TextBox2.Text) - CInt(Me.TextBox1.Text) + 1
End If
End If
End Sub
End Class