Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > การวนลูป ใน PrintDocument ของ vb ครับ รบกวนผู้เชี่ยวชาญหน่อยครับ



 

การวนลูป ใน PrintDocument ของ vb ครับ รบกวนผู้เชี่ยวชาญหน่อยครับ

 



Topic : 133118



โพสกระทู้ ( 17 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook



การวนลูป ใน PrintDocument ของ vb ครับ

รบกวนผู้เชี่ยวชาญทั้งหลายครับ ช่วยดูโค้ดให้หน่อยครับ ไม่แนใจว่าผมวนลูปอะไรผิดหรือเปล่า
ผมต้องการให้เมื่อเลือกข้อมูลครับที่ต้องการ ให้ขึ้นบรรทัดใหม่ทันที

แรกๆๆ ก็ไปได้สวย พอเริ่มพิมพ์ครั้งที่ 3 กลับไม่มีข้อมูลครับ
รบกวนหน่อยนะครับ

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
If DataGridView2.Rows.Count = 0 Then
_Error("กรุณาเลือกรายการคนต่างด้าวที่ต้องการพิมพ์เอกสาร")
Else
If TextBox1.Text = "" Then
_Error("กรุณาระบุลักษณะงานที่ให้คนต่างด้าวทำ")
TextBox1.Select()
Else
Lineperpage = 12
PrintPreviewDialog2.ShowDialog()
PrintDialog2.Document = Me.PrintDocument2
If PrintDialog2.ShowDialog = Windows.Forms.DialogResult.OK Then
PrintDialog2.PrinterSettings = PrintDocument2.PrinterSettings
Dim ps As New PaperSize("A4Landscape", 1169, 807)
' ps.PaperName = PaperKind.A4
' New_Paper.PaperName = PaperKind.Custom
Dim New_Margin As New Margins
New_Margin.Left = 0
New_Margin.Top = 50
With PrintDocument2
.DefaultPageSettings.PaperSize = ps
.DefaultPageSettings.Margins = New_Margin
.PrinterSettings.DefaultPageSettings.Landscape = False
.Print()
End With
End If
End If
End If
End Sub
Private Sub PrintDocument2_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument2.PrintPage
Dim newImage As Image = My.Resources.businessman
Dim row As Integer = 490
Dim col As Integer = 160
Dim row1 As Integer = 452
Dim row2 As Integer = 498
Dim col1 As Integer = 43
Dim printFont As New Font("TH SarabunPSK", 16)
Dim printFont3 As New Font("TH SarabunPSK", 11)
Dim printFont2 As New Font("TH SarabunPSK", 18, FontStyle.Bold)
Dim printposition As New PointF
Dim printposition2 As New PointF
Dim printcolor As New SolidBrush(Color.Black)
' Dim i As Integer
Dim width As Integer = 100
Dim heigth As Integer = 100
Dim monthnow1 As String

If CStr(Month(Date.Now)) = "1" Then
monthnow1 = "มกราคม"
ElseIf CStr(Month(Date.Now)) = "2" Then
monthnow1 = "กุมภาพันธ์"
ElseIf CStr(Month(Date.Now)) = "3" Then
monthnow1 = "มีนาคม"
ElseIf CStr(Month(Date.Now)) = "4" Then
monthnow1 = "เมษายน"
ElseIf CStr(Month(Date.Now)) = "5" Then
monthnow1 = "พฤษภาคม"
ElseIf CStr(Month(Date.Now)) = "6" Then
monthnow1 = "มิถุนายน"
ElseIf CStr(Month(Date.Now)) = "7" Then
monthnow1 = "กรกฏาคม"
ElseIf CStr(Month(Date.Now)) = "8" Then
monthnow1 = "สิงหาคม"
ElseIf CStr(Month(Date.Now)) = "9" Then
monthnow1 = "กันยายน"
ElseIf CStr(Month(Date.Now)) = "10" Then
monthnow1 = "ตุลาคม"
ElseIf CStr(Month(Date.Now)) = "11" Then
monthnow1 = "พฤศจิกายน"
ElseIf CStr(Month(Date.Now)) = "12" Then
monthnow1 = "ธันวาคม"
End If

Try
Statement =
" SELECT * " &
" From employer" &
" WHERE " &
" noemployer = " & "'" & Label8.Text & "'"
cmd = New OleDbCommand(Statement, cn)
dr = cmd.ExecuteReader
dr.Read()
e.Graphics.DrawString("____________________________", printFont, printcolor, 550, 43)
e.Graphics.DrawString("____________________________", printFont, printcolor, 550, 153)
e.Graphics.DrawString("| |", printFont, printcolor, 550, 56)
e.Graphics.DrawString("| |", printFont, printcolor, 550, 70)
e.Graphics.DrawString("| |", printFont, printcolor, 550, 84)
e.Graphics.DrawString("| |", printFont, printcolor, 550, 98)
e.Graphics.DrawString("| |", printFont, printcolor, 550, 112)
e.Graphics.DrawString("| |", printFont, printcolor, 550, 126)
e.Graphics.DrawString("| |", printFont, printcolor, 550, 140)
e.Graphics.DrawString("| |", printFont, printcolor, 550, 154)
e.Graphics.DrawString(" สำหรับเจ้าหน้าที่", printFont, printcolor, 590, 65)
e.Graphics.DrawString(" เลขรับที่......................................", printFont, printcolor, 555, 95)
e.Graphics.DrawString(" วันที่...........................................", printFont, printcolor, 555, 120)
e.Graphics.DrawString(" ลงชื่อ................................ผู้รับแจ้ง", printFont, printcolor, 555, 145)
e.Graphics.DrawString("แบบแจ้งการจ้างคนต่างด้าว", printFont2, printcolor, 320, 180)
e.Graphics.DrawString("วันที่.........เดือน.........................พ.ศ..........", printFont, printcolor, 520, 230)
' e.Graphics.DrawString("" & Day(Now.ToString) & " ", printFont, printcolor, 550, 225)
e.Graphics.DrawString("" & monthnow1 & "", printFont, printcolor, 620, 225)
e.Graphics.DrawString("" & Year(Date.Now) + 543 & "", printFont, printcolor, 730, 225)
' e.Graphics.DrawString("" & mnnow & "", printFont, printcolor, 250, 225)
e.Graphics.DrawString("ชื่อนายจ้าง............................................................................................................................เลขบัตรประจำตัว", printFont, printcolor, 150, 260)

e.Graphics.DrawString("" & dr.Item("nameemployer").ToString & "", printFont, printcolor, 250, 255)
e.Graphics.DrawString("ประชาชน/เลขทะเบียนนิติบุคคล.............................................................ประเภทกิจการ.....................................................", printFont, printcolor, 60, 290)
e.Graphics.DrawString("" & dr.Item("noemployer").ToString & "", printFont, printcolor, 260, 285)
e.Graphics.DrawString("" & dr.Item("typework").ToString & "", printFont, printcolor, 570, 285)
e.Graphics.DrawString("ที่ตั้งเลขที่.....................หมู่ที่............ซอย..................................ถนน................................ตำบล/แขวง...................................", printFont, printcolor, 60, 320)
e.Graphics.DrawString("" & dr.Item("noy").ToString & "", printFont, printcolor, 130, 315)
e.Graphics.DrawString("" & dr.Item("mu").ToString & "", printFont, printcolor, 230, 315)
e.Graphics.DrawString("" & dr.Item("lane").ToString & "", printFont, printcolor, 330, 315)
e.Graphics.DrawString("" & dr.Item("road").ToString & "", printFont, printcolor, 470, 315)
e.Graphics.DrawString("" & dr.Item("tambol").ToString & "", printFont, printcolor, 650, 315)
e.Graphics.DrawString("อำเภอ/เขต......................................จังหวัด..............................................เบอร์โทรศัพท์.........................................", printFont, printcolor, 60, 350)
e.Graphics.DrawString("" & dr.Item("district").ToString & "", printFont, printcolor, 130, 345)
e.Graphics.DrawString("" & dr.Item("Province").ToString & "", printFont, printcolor, 310, 345)
e.Graphics.DrawString("" & dr.Item("tel").ToString & "", printFont, printcolor, 560, 345)
e.Graphics.DrawString("ขอแจ้งว่าได้จ้างคนต่างด้าวดังต่อไปนี้ เพื่อให้ทำงาน (ลักษณะงานที่ให้คนต่างด้าวทำ).....................................", printFont, printcolor, 150, 380)
e.Graphics.DrawString("" & TextBox1.Text & "", printFont, printcolor, 650, 375)
e.Graphics.DrawString("ตั้งแต่วันที่...........เดือน.............................พ.ศ...............", printFont, printcolor, 60, 410)
e.Graphics.DrawString("" & monthnow1 & "", printFont, printcolor, 200, 405)
e.Graphics.DrawString("" & Year(Date.Now) + 543 & "", printFont, printcolor, 330, 405)
e.Graphics.DrawString("___________________________________________________________________________________________", printFont, printcolor, 60, 438)
e.Graphics.DrawString("___________________________________________________________________________________________", printFont, printcolor, 60, 468)
e.Graphics.DrawString("ลำดับ", printFont, printcolor, 66, 460)
e.Graphics.DrawString("ชื่อ-สกุล", printFont, printcolor, 200, 460)
e.Graphics.DrawString("สัญชาติ", printFont, printcolor, 355, 460)
e.Graphics.DrawString("เพศ", printFont, printcolor, 410, 460)
e.Graphics.DrawString("อายุ", printFont, printcolor, 450, 460)
e.Graphics.DrawString("เลขที่ใบอนุญาตทำงาน", printFont, printcolor, 500, 460)
e.Graphics.DrawString("เลขที่หนังสือเดินทาง", printFont, printcolor, 650, 460)
Dim o As Integer = 1
For Me.I_counter = I_Start To DataGridView2.Rows.Count - 1 ตรงนี้ต้องการให้วนรูป เมื่อครับ 13 รายการแล้ว ขึ้นหน้าใหม่
e.Graphics.DrawString("" & o & "", printFont, printcolor, 80, row)
e.Graphics.DrawString("" & DataGridView2.Rows(I_counter).Cells(2).Value.ToString & "", printFont, printcolor, 655, row)
e.Graphics.DrawString("" & DataGridView2.Rows(I_counter).Cells(3).Value.ToString & "", printFont, printcolor, 105, row)
e.Graphics.DrawString("" & DataGridView2.Rows(I_counter).Cells(4).Value.ToString & "", printFont, printcolor, 356, row)
e.Graphics.DrawString("" & DataGridView2.Rows(I_counter).Cells(7).Value.ToString & "", printFont, printcolor, 405, row)
e.Graphics.DrawString("" & DataGridView2.Rows(I_counter).Cells(6).Value.ToString & "", printFont, printcolor, 450, row)
e.Graphics.DrawString("" & DataGridView2.Rows(I_counter).Cells(8).Value.ToString & "", printFont, printcolor, 500, row)
HH += 20
row = row + 30
Linenumber += 1
o = o + 1
If Linenumber = Lineperpage Then
Linenumber = 0
I_Start = I_counter + 1
HH = 50
e.HasMorePages = True
Exit For
End If
Next

For ii = 0 To 11
e.Graphics.DrawString("___________________________________________________________________________________________", printFont, printcolor, 60, row2)
row2 = row2 + 30
Next
ii = ii + 1
For i = 0 To 34

printposition2 = New PointF(col1, row1)
e.Graphics.DrawString("|", printFont, printcolor, 60, row1)
e.Graphics.DrawString("|", printFont, printcolor, 100, row1)
e.Graphics.DrawString("|", printFont, printcolor, 350, row1)
e.Graphics.DrawString("|", printFont, printcolor, 400, row1)
e.Graphics.DrawString("|", printFont, printcolor, 440, row1)
e.Graphics.DrawString("|", printFont, printcolor, 480, row1)
e.Graphics.DrawString("|", printFont, printcolor, 645, row1)
e.Graphics.DrawString("|", printFont, printcolor, 770, row1)
row1 = row1 + 11
Next
i = i + 1
e.Graphics.DrawString("ขอรับรองว่าข้อความข้างต้นเป็นจริงทุกประการ", printFont, printcolor, 60, 900)
e.Graphics.DrawString("ลงชื่อ.............................................................", printFont, printcolor, 60, 930)
e.Graphics.DrawString(" (........................................................)", printFont, printcolor, 60, 960)
e.Graphics.DrawString(" นายจ้าง", printFont, printcolor, 60, 990)
e.Graphics.DrawString("ลงชื่อ.............................................................", printFont, printcolor, 490, 900)
e.Graphics.DrawString(" (........................................................)", printFont, printcolor, 490, 930)
e.Graphics.DrawString(" นายทะเบียน", printFont, printcolor, 490, 960)
e.Graphics.DrawString(" วันที่...........เดือน........................พ.ศ.........", printFont, printcolor, 490, 990)


dr.Close()
cmd.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message, "ข้อผิดพลาด กรุณาทำรายการใหม่", MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try
End Sub



Tag : .NET







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2019-02-12 20:01:59 By : 1639518442828154 View : 898 Reply : 1
 

 

No. 1

Guest


ก็เคยประสบณ์ปัญหานี้เหมือนกันครับ ผมสันิฐานว่ามันลูปเร็วจนดึงข้อมูลไม่ทัน ดังนั้นผมแก้โดยให้มันลูปช้าลงหน่อย โดยใช้ timer หน่วงเวลาไว้ให้ 1 วินาที หรือมากกว่า ปริ๊นต์ 1 ครั้ง หรือ ลูป 1 ครั้ง ซึ่งได้ผล ดี ตามที่ต้องการ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2019-02-15 21:49:16 By : pakyaudio
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : การวนลูป ใน PrintDocument ของ vb ครับ รบกวนผู้เชี่ยวชาญหน่อยครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่