Private Sub bt_print_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_print.Click If list1.Rows.Count = 0 Then MsgBox("条码打印完毕!") Exit Sub End If Dim Thread As New System.Threading.Thread(AddressOf BarcodePrint) Thread.Start() End Sub Private Sub BarcodePrint()
Dim jsq As Integer = 0 Dim i As Integer For i = 0 To list1.Rows.Count - 1 Dim s As Integer = list1.Rows(i).Cells(4).Value jsq += s Next Dim hang As Integer Dim sz As Double = Math.Round(jsq / 3, 1) Dim wei As Integer = Microsoft.VisualBasic.Right(sz, 1) If wei < 4 And wei > 0 And sz.ToString.IndexOf(".") > -1 Then hang = Math.Round(jsq / 3, 1) + 1 Else hang = Math.Round(jsq / 3, 1) End If Dim i2 As Integer For i2 = 1 To hang Img() jian() BarPrint() Thread.Sleep(1000) Next bt_print.Enabled = False MsgBox("打印完成!") End Sub Sub BarPrint() Try Dim myprintdg As PrintDialog = New PrintDialog myprintdg.Document = PrintDocument1 myprintdg.PrinterSettings.Copies = 1 PrintDocument1.Print() Catch ex As Exception MsgBox(ex.ToString) End Try End Sub Sub jian() Try Dim quantity As Integer quantity = list1.Rows(0).Cells(4).Value If quantity = 1 Then If list1.Rows.Count > 1 Then Dim q1 As Integer = list1.Rows(1).Cells(4).Value If q1 = 1 Then If list1.Rows.Count > 2 Then If list1.Rows(2).Cells(4).Value = 1 Then list1.Rows.RemoveAt(2) Else list1.Rows(2).Cells(4).Value = list1.Rows(2).Cells(4).Value - 1 End If list1.Rows.RemoveAt(0) End If ElseIf q1 = 2 Then list1.Rows.RemoveAt(0) ElseIf q1 >= 3 Then list1.Rows(1).Cells(4).Value = q1 - 2 End If End If list1.Rows.RemoveAt(0) ElseIf quantity = 2 Then If list1.Rows.Count > 1 Then If list1.Rows(1).Cells(4).Value = 1 Then list1.Rows.RemoveAt(1) Else list1.Rows(1).Cells(4).Value = list1.Rows(1).Cells(4).Value - 1 End If list1.Rows.RemoveAt(0) End If ElseIf quantity = 3 Then list1.Rows.RemoveAt(0) Else list1.Rows(0).Cells(4).Value = list1.Rows(0).Cells(4).Value - 3 End If Catch ex As Exception MsgBox(ex.ToString) End Try End Sub Sub Img() Try Dim rid, aid As String Dim quantity As Integer quantity = list1.Rows(0).Cells(4).Value rid = list1.Rows(0).Cells(0).Value aid = list1.Rows(0).Cells(5).Value If quantity = 1 Then ImageShow1(aid, rid) If list1.Rows.Count > 1 Then Dim two_rid, two_aid As String two_rid = list1.Rows(1).Cells(0).Value two_aid = list1.Rows(1).Cells(5).Value Dim two_quantity As Integer = list1.Rows(1).Cells(4).Value If two_quantity >= 2 Then ImageShow2(two_aid, two_rid) ImageShow3(two_aid, two_rid) Else If list1.Rows.Count > 2 Then Dim three_rid, three_aid As String three_rid = list1.Rows(2).Cells(0).Value three_aid = list1.Rows(2).Cells(5).Value ImageShow2(two_aid, two_rid) ImageShow3(three_aid, three_rid) Else ImageShow2(two_aid, two_rid) ImageShow3("", "") End If End If Else ImageShow2("", "") ImageShow3("", "") End If ElseIf quantity = 2 Then If list1.Rows.Count > 1 Then Dim two_rid, two_aid As String two_rid = list1.Rows(1).Cells(0).Value two_aid = list1.Rows(1).Cells(5).Value ImageShow1(aid, rid) ImageShow2(aid, rid) ImageShow3(two_aid, two_rid) Else ImageShow1(aid, rid) ImageShow2(aid, rid) ImageShow3("", "") End If Else ImageShow1(aid, rid) ImageShow2(aid, rid) ImageShow3(aid, rid) End If Catch ex As Exception MsgBox(ex.ToString) End Try End Sub 最后自己用傻招实现
for(var i =0; i< 标签数组.length; i++)
{
列++;
if(列==1)
{
PictureBox1.Image= 加载Image(标签数组[i]);
e.Graphics.DrawImage(PictureBox1.Image, 20, 0, 90, 58)
}
else if(列==2)
{
PictureBox2.Image= 加载Image(标签数组[i]);
e.Graphics.DrawImage(PictureBox2.Image, 154, 0, 90, 58)
}
else if(列==3)
{
PictureBox3.Image= 加载Image(标签数组[i]);
e.Graphics.DrawImage(PictureBox3.Image, 288, 0, 90, 58)
打印并且换页();
列=0;
}
}
if(列!=0)
{
打印并且换页();
}
int 行=0;
for(var i =0; i< 标签数组.length; i++)
{
列++;
行++;
if(列==1)
{
PictureBox1.Image= 加载Image(标签数组[i]);
e.Graphics.DrawImage(PictureBox1.Image, 20, 0, 90, 58)
}
else if(列==2)
{
PictureBox2.Image= 加载Image(标签数组[i]);
e.Graphics.DrawImage(PictureBox2.Image, 154, 0, 90, 58)
}
else if(列==3)
{
PictureBox3.Image= 加载Image(标签数组[i]);
e.Graphics.DrawImage(PictureBox3.Image, 288, 0, 90, 58)
if(行==10)
{
打印并且换页();
行=0;
}
列=0;
}
}
if(列!=0)
{
打印并且换页();
}
int 行=0;
for(var i =0; i< 标签数组.length; i++)
{
列++;
if(列==1)
{
PictureBox1.Image= 加载Image(标签数组[i]);
e.Graphics.DrawImage(PictureBox1.Image, 20, 0, 90, 58)
}
else if(列==2)
{
PictureBox2.Image= 加载Image(标签数组[i]);
e.Graphics.DrawImage(PictureBox2.Image, 154, 0, 90, 58)
}
else if(列==3)
{
PictureBox3.Image= 加载Image(标签数组[i]);
e.Graphics.DrawImage(PictureBox3.Image, 288, 0, 90, 58)
行++;
if(行==10)
{
打印并且换页();
行=0;
}
列=0;
}
}
if(列!=0)
{
打印并且换页();
}
int 行=0;
for(var i =0; i< 标签数组.length; i++)
{
列++;
行++;
if(列==1)
{
PictureBox1.Image= 加载Image(标签数组[i]);
e.Graphics.DrawImage(PictureBox1.Image, 20, 0, 90, 58)
}
else if(列==2)
{
PictureBox2.Image= 加载Image(标签数组[i]);
e.Graphics.DrawImage(PictureBox2.Image, 154, 0, 90, 58)
}
else if(列==3)
{
PictureBox3.Image= 加载Image(标签数组[i]);
e.Graphics.DrawImage(PictureBox3.Image, 288, 0, 90, 58)
if(行==10)
{
打印并且换页();
行=0;
}
列=0;
}
}
if(列!=0)
{
打印并且换页();
}
If list1.Rows.Count = 0 Then
MsgBox("条码打印完毕!")
Exit Sub
End If
Dim Thread As New System.Threading.Thread(AddressOf BarcodePrint)
Thread.Start() End Sub
Private Sub BarcodePrint()
Dim jsq As Integer = 0
Dim i As Integer
For i = 0 To list1.Rows.Count - 1
Dim s As Integer = list1.Rows(i).Cells(4).Value
jsq += s
Next
Dim hang As Integer
Dim sz As Double = Math.Round(jsq / 3, 1)
Dim wei As Integer = Microsoft.VisualBasic.Right(sz, 1)
If wei < 4 And wei > 0 And sz.ToString.IndexOf(".") > -1 Then
hang = Math.Round(jsq / 3, 1) + 1
Else
hang = Math.Round(jsq / 3, 1)
End If Dim i2 As Integer
For i2 = 1 To hang
Img()
jian()
BarPrint()
Thread.Sleep(1000)
Next bt_print.Enabled = False
MsgBox("打印完成!") End Sub
Sub BarPrint()
Try
Dim myprintdg As PrintDialog = New PrintDialog
myprintdg.Document = PrintDocument1
myprintdg.PrinterSettings.Copies = 1
PrintDocument1.Print()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Sub jian()
Try
Dim quantity As Integer
quantity = list1.Rows(0).Cells(4).Value
If quantity = 1 Then
If list1.Rows.Count > 1 Then
Dim q1 As Integer = list1.Rows(1).Cells(4).Value
If q1 = 1 Then
If list1.Rows.Count > 2 Then
If list1.Rows(2).Cells(4).Value = 1 Then
list1.Rows.RemoveAt(2)
Else
list1.Rows(2).Cells(4).Value = list1.Rows(2).Cells(4).Value - 1
End If
list1.Rows.RemoveAt(0)
End If
ElseIf q1 = 2 Then
list1.Rows.RemoveAt(0)
ElseIf q1 >= 3 Then
list1.Rows(1).Cells(4).Value = q1 - 2
End If
End If list1.Rows.RemoveAt(0) ElseIf quantity = 2 Then
If list1.Rows.Count > 1 Then
If list1.Rows(1).Cells(4).Value = 1 Then
list1.Rows.RemoveAt(1)
Else
list1.Rows(1).Cells(4).Value = list1.Rows(1).Cells(4).Value - 1
End If
list1.Rows.RemoveAt(0)
End If ElseIf quantity = 3 Then
list1.Rows.RemoveAt(0)
Else
list1.Rows(0).Cells(4).Value = list1.Rows(0).Cells(4).Value - 3
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try End Sub
Sub Img()
Try
Dim rid, aid As String
Dim quantity As Integer
quantity = list1.Rows(0).Cells(4).Value
rid = list1.Rows(0).Cells(0).Value
aid = list1.Rows(0).Cells(5).Value If quantity = 1 Then
ImageShow1(aid, rid)
If list1.Rows.Count > 1 Then
Dim two_rid, two_aid As String
two_rid = list1.Rows(1).Cells(0).Value
two_aid = list1.Rows(1).Cells(5).Value
Dim two_quantity As Integer = list1.Rows(1).Cells(4).Value
If two_quantity >= 2 Then
ImageShow2(two_aid, two_rid)
ImageShow3(two_aid, two_rid)
Else
If list1.Rows.Count > 2 Then
Dim three_rid, three_aid As String
three_rid = list1.Rows(2).Cells(0).Value
three_aid = list1.Rows(2).Cells(5).Value
ImageShow2(two_aid, two_rid)
ImageShow3(three_aid, three_rid)
Else
ImageShow2(two_aid, two_rid)
ImageShow3("", "")
End If
End If
Else
ImageShow2("", "")
ImageShow3("", "")
End If
ElseIf quantity = 2 Then If list1.Rows.Count > 1 Then
Dim two_rid, two_aid As String
two_rid = list1.Rows(1).Cells(0).Value
two_aid = list1.Rows(1).Cells(5).Value
ImageShow1(aid, rid)
ImageShow2(aid, rid)
ImageShow3(two_aid, two_rid)
Else
ImageShow1(aid, rid)
ImageShow2(aid, rid)
ImageShow3("", "")
End If Else
ImageShow1(aid, rid)
ImageShow2(aid, rid)
ImageShow3(aid, rid)
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try End Sub
最后自己用傻招实现