|
สำหรับสาย VB6 + ActiveReports 2.0 สามารถอ่านรายละเอียดและดาวน์โหลดโค้ดได้ที่หัวข้อ โค้ดการพิมพ์ชื่อที่อยู่ผู้รับออกซองจดหมายขนาด 23x11 ซม. ด้วย ActiveReports 2.0 ... ในส่วนของรายละเอียดวิธีการขั้นตอนต่างๆ แอดมินจะขอข้ามไปเพราะได้เคยกล่าวนำไปหลายครั้งแล้ว สำหรับมิตรรักแฟนคลับสายพันธุ์ Visual Basic ที่เผลอพลัดหลงเข้ามาเห็นเว็บไซต์แห่งนี้ จงใช้ความพยายามในการค้นหาข้อมูลพื้นฐาน หรือการใช้งานเบื้องต้นของ ActiveReports เอาเองด้วยเถิดครับผม ...
การใช้งาน ActiveReports Designer ...
l
มาดูโค้ดในส่วนของฟอร์มหลัก ...
- ' / --------------------------------------------------------------------
- ' / Developer : Mr.Surapon Yodsanga (Thongkorn Tubtimkrob)
- ' / eMail : thongkorn@hotmail.com
- ' / URL: http://www.g2gnet.com (Khon Kaen - Thailand)
- ' / Facebook: https://www.facebook.com/g2gnet (For Thailand)
- ' / Facebook: https://www.facebook.com/commonindy (Worldwide)
- ' / Purpose : Print out standard envelope 23x11 cm. with ActiveReports.NET 6.0
- ' / Microsoft Visual Basic .NET (2010) SP1
- ' / This is open source code under @CopyLeft by Thongkorn Tubtimkrob.
- ' / You can modify and/or distribute without to inform the developer.
- ' / --------------------------------------------------------------------
- Imports DataDynamics.ActiveReports
- Public Class frmPrintEnvelope
- ' / --------------------------------------------------------------------
- Private Sub frmPrintEnvelope_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
- txtAddress.Text = _
- "กรุณาส่ง" & vbCrLf & _
- "นายทองก้อน ทับทิมกรอบ" & vbCrLf & _
- "555 ม.555 ซ.ห้าห้าห้า ถ.กลางเมือง" & vbCrLf & _
- "ต.เมืองเก่า อ.เมือง" & vbCrLf & _
- "จ.ขอนแก่น 40000"
- '// ตั้งค่า ActiveReports
- Viewer1.ReportViewer.Zoom = 0.75F ' Zoom = 75%
- Viewer1.ReportViewer.DisplayUnits = Viewer.DisplayUnits.Metric
- '// Form Minimum Size
- Me.MinimumSize = New Size(781, 631)
- '// ตั้งค่าการพิมพ์จากขอบซ้ายของซองจดหมาย
- txtLeftMargin.Text = "80"
- '// ตั้งค่าการพิมพ์จากด้านบน
- txtTopMargin.Text = "25"
- '// Initialize Font
- lblDataFont.Font = New Font("BrowalliaUPC", "16")
- lblDataFont.Text = lblDataFont.Font.Name & " " & lblDataFont.Font.Size
- End Sub
- ' / --------------------------------------------------------------------
- Private Sub btnPrintPreview_Click(sender As System.Object, e As System.EventArgs) Handles btnPrintPreview.Click
- If txtLeftMargin.Text = "" Then txtLeftMargin.Text = "80"
- If txtTopMargin.Text = "" Then txtTopMargin.Text = "25"
- '/ Instance name ARDesigner มันจะชี้ไปที่ไฟล์ arPrintEnvelope.vb
- Dim rpt As New arPrintEnvelope()
- '/ โหลดรายงาน document (arPrintEnvelope) เข้าสู่ ActiveReports Viewer
- Me.Viewer1.Document = rpt.Document
- '/ Run Report
- rpt.Run()
- End Sub
- ' / --------------------------------------------------------------------
- Private Sub btnFont_Click(sender As System.Object, e As System.EventArgs) Handles btnFont.Click
- Dim FontDialog As FontDialog = New FontDialog
- '// FontDialog รับค่าปัจจุบันจาก lblDataFont
- FontDialog.Font = New Font(lblDataFont.Font.Name, lblDataFont.Font.Size, lblDataFont.Font.Style)
- If FontDialog.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
- lblDataFont.Font = FontDialog.Font
- lblDataFont.Text = lblDataFont.Font.Name & " " & lblDataFont.Font.Size
- End If
- End Sub
- ' / --------------------------------------------------------------------
- ' / ก่อนใช้งาน Form_KeyDown ได้ ต้องกำหนดค่าให้ KeyPreview = True ก่อน
- Private Sub frmPrintEnvelope_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
- Select Case e.KeyCode
- Case Keys.F7
- Call btnPrintPreview_Click(sender, e)
- Case Keys.F10
- Call btnExit_Click(sender, e)
- End Select
- End Sub
- ' / --------------------------------------------------------------------
- Private Sub txtLeftMargin_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtLeftMargin.KeyPress
- '// หากกด Enter
- If e.KeyChar = Chr(13) Then
- e.Handled = True
- '// เลื่อนไป Control ถัดไป
- SendKeys.Send("{TAB}")
- Else
- '// เช็คการกดคีย์ให้รับเฉพาะ 0 - 9 เท่านั้น
- e.Handled = CheckDigitOnly(Asc(e.KeyChar))
- End If
- End Sub
- ' / --------------------------------------------------------------------
- Private Sub txtTopMargin_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtTopMargin.KeyPress
- '// หากกด Enter
- If e.KeyChar = Chr(13) Then
- e.Handled = True
- '// เลื่อนไป Control ถัดไป
- SendKeys.Send("{TAB}")
- Else
- '// เช็คการกดคีย์ให้รับเฉพาะ 0 - 9 เท่านั้น
- e.Handled = CheckDigitOnly(Asc(e.KeyChar))
- End If
- End Sub
- ' / --------------------------------------------------------------------
- ' / ฟังค์ชั่นในการป้อนเฉพาะค่าตัวเลขได้เท่านั้น
- Function CheckDigitOnly(ByVal index As Byte) As Boolean
- Select Case index
- Case 48 To 57 ' เลข 0 - 9
- CheckDigitOnly = False
- Case 8, 13 ' Backspace = 8, Enter = 13
- CheckDigitOnly = False
- Case Else
- CheckDigitOnly = True
- End Select
- End Function
- Private Sub frmPrintEnvelope_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
- Me.Dispose()
- Application.Exit()
- End Sub
- Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
- Me.Close()
- End Sub
- Private Sub ToolStripStatusLabel2_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripStatusLabel2.Click
- Process.Start("http://www.facebook.com/g2gnet")
- End Sub
- End Class
คัดลอกไปที่คลิปบอร์ด
มาดูโค้ดในส่วนของ ActiveReports Designer ...
- ' / --------------------------------------------------------------------
- ' / Developer : Mr.Surapon Yodsanga (Thongkorn Tubtimkrob)
- ' / eMail : thongkorn@hotmail.com
- ' / URL: http://www.g2gnet.com (Khon Kaen - Thailand)
- ' / Facebook: https://www.facebook.com/g2gnet (For Thailand)
- ' / Facebook: https://www.facebook.com/commonindy (Worldwide)
- ' / Purpose : Print out standard envelope 23x11 cm. with ActiveReports.NET 6.0
- ' / Microsoft Visual Basic .NET (2010) SP1
- ' / This is open source code under @CopyLeft by Thongkorn Tubtimkrob.
- ' / You can modify and/or distribute without to inform the developer.
- ' / --------------------------------------------------------------------
- Imports DataDynamics.ActiveReports
- Imports DataDynamics.ActiveReports.Document
- Public Class arPrintEnvelope
- Private Sub Detail1_Format(sender As System.Object, e As System.EventArgs) Handles Detail1.Format
- txtRecipient.Text = frmPrintEnvelope.txtAddress.Text
- End Sub
- Private Sub arPrintEnvelope_ReportStart(sender As Object, e As System.EventArgs) Handles Me.ReportStart
- ' จะเริ่มต้นการทำงานที่โปรแกรมย่อยตัวนี้
- ' การตั้งค่าแบบ Run Time (มีหน่วยวัดเป็นนิ้ว)
- With PageSettings
- .Margins.Left = 0.25
- .Margins.Right = 0.25
- .Margins.Top = 0.5
- .Margins.Bottom = 0.5
- ' ตั้งค่ากระดาษแนวตั้ง
- .Orientation = PageOrientation.Landscape
- ' ซองจดหมาย หรือ Envelope #10, ขนาด 4 1/8 x 9 1/2 in
- .PaperKind = Drawing.Printing.PaperKind.Number10Envelope
- ' กรณีที่กำหนดขนาดกระดาษเอง
- ' .PaperKind = Drawing.Printing.PaperKind.Custom
- End With
- ' ความสูงของการพิมพ์ Detail
- Detail1.Height = CmToInch(7.5) ' วัดระยะโดยประมาณ 7.5 ซม แต่แปลงเป็นนิ้ว)
- ' กำหนดระยะการพิมพ์ที่อยู่ (รับค่าเป็นมิลลิเมตรเข้ามาหาร 10 เป็น ซม. แล้วแปลงเป็นนิ้ว)
- txtRecipient.Top = ActiveReport.CmToInch(Val(frmPrintEnvelope.txtTopMargin.Text) / 10)
- txtRecipient.Left = ActiveReport.CmToInch(Val(frmPrintEnvelope.txtLeftMargin.Text) / 10)
- ' กำหนดฟอนต์
- txtRecipient.Font = frmPrintEnvelope.lblDataFont.Font
- End Sub
- End Class
คัดลอกไปที่คลิปบอร์ด สาระสำคัญในส่วนของ AR Designer คือ ReportStart จะเป็นการเริ่มต้นตั้งค่าการพิมพ์ และนำข้อมูลมาพิมพ์ที่โปรแกรมย่อย Detail1_Format ...
ดาวน์โหลดโค้ดต้นฉบับ VB.NET (2010) และ AR6 ได้ที่นี่ ...
|
ขออภัย! โพสต์นี้มีไฟล์แนบหรือรูปภาพที่ไม่ได้รับอนุญาตให้คุณเข้าถึง
คุณจำเป็นต้อง ลงชื่อเข้าใช้ เพื่อดาวน์โหลดหรือดูไฟล์แนบนี้ คุณยังไม่มีบัญชีใช่ไหม? ลงทะเบียน
x
|