Imports System.Drawing.Printing
Public Class Form_Print_Barcode
Dim w, q As Double
Dim dd, ss, rr, tt, a, b, z, n, n3, v, h, i, j, u, k, g, o As Integer
Dim printFont As New Font _
("3 of 9 Barcode", 36, System.Drawing.FontStyle.Regular)
Dim printFont2 As New Font _
("Angsana New", 22, System.Drawing.FontStyle.Regular)
Dim iPage As Integer = 1
Dim str As String
Private WithEvents docToPrint As New Printing.PrintDocument
Private Sub Form_Print_Barcode_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Num1.Text = 23
Num3.Text = ""
Me.KeyPreview = True
End Sub
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Try
k = Convert.ToInt32(Num1.Text)
If (k < 10 And Num1.Text.Length < 2) Then
Num1.Text = "0" & Num1.Text
End If
g = Convert.ToInt32(Num3.Text)
If (Num2.Text <> "" And Num3.Text <> "") Then
Num2.Text = Val(Num2.Text)
j = Convert.ToInt32(Num2.Text)
If (j < 10) Then
Num2.Text = "0" & Num2.Text
End If
dd = 33 : ss = 40 : rr = 70 : tt = 95 : a = 1 : n = 0 : h = 0 : v = 0 : i = 0 : z = 0
n3 = Convert.ToInt32(Num3.Text)
q = n3 / 44
w = Math.Ceiling(q)
PrintPreviewControl1.Rows = w
PrintPreviewControl1.Columns = 3
PrintPreviewControl1.Zoom = 0.75
PrintPreviewControl1.Columns = 1
PrintPreviewControl1.Document = PrintDocument1
PrintPreviewControl1.InvalidatePreview()
End If
Catch ex As Exception
MessageBox.Show("กรุณาตรวจสอบรหัสและใส่รหัสใหม่อีกครั้ง", "กรุณากรอกรหัสใหม่", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Num3.Text = ""
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dd = 33 : ss = 40 : rr = 70 : tt = 95 : a = 1 : n = 0 : h = 0 : v = 0 : i = 0 : z = 0
n3 = Convert.ToInt32(Num3.Text)
q = n3 / 44
w = Math.Ceiling(q)
Dim ps As New Printing.PrinterSettings
PrintDocument1.PrinterSettings.MinimumPage = 1
PrintDocument1.PrinterSettings.MaximumPage = w
PrintDocument1.PrinterSettings.FromPage = 2
PrintDocument1.PrinterSettings.ToPage = 2
If PrintDialog1.ShowDialog = DialogResult.OK Then
PrintDocument1.Print()
End If
End Sub
Private Sub PrintDocument1_PrintPage_1(ByVal sender As System.Object, ByVal x As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Try
n = a + 4
If (w = 1 And h = 0) Then
h += 1
v = Convert.ToInt32(Num3.Text)
ElseIf (w > 1 And h = 0) Then
h += 1
v = 44
End If
While (a <= v)
i = a
While (a < n)
If (a < 10) Then
str = Num1.Text & Num2.Text & "0" & a
Else
str = Num1.Text & Num2.Text & a
End If
x.Graphics.DrawString(str, printFont, _
System.Drawing.Brushes.Black, dd, ss)
dd += 190
a += 1
If (a > n3) Then
Exit While
Else
End If
End While
a = i
While (a < n)
If (a < 10) Then
str = Num1.Text & Num2.Text & "0" & a
Else
str = Num1.Text & Num2.Text & a
End If
x.Graphics.DrawString(str, printFont2, _
System.Drawing.Brushes.Black, tt, rr)
tt += 192
a += 1
If (a > n3) Then
Exit While
Else
End If
End While
ss += 100
rr += 100
dd = 33
tt = 95
n = a + 4
End While
z += 1
If (z < w) Then
x.HasMorePages = True
End If
dd = 33
ss = 40
rr = 70
tt = 95
If ((n3 - a) < 44) Then
v = n3
ElseIf ((n3 - a) > 44) Then
v += 44
Else
End If
Catch ex As Exception
MessageBox.Show("กรุณาตรวจสอบรหัสและใส่รหัสใหม่อีกครั้ง", "กรุณากรอกรหัสใหม่", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Num1.Text = ""
Num3.Text = ""
End Try
End Sub
End Class