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,038

HOME > .NET Framework > Forum > ขอโค๊ด สั่งปริ้นauto VB.net 2010 จากฟอร์ม ReportViewer ครับ


 

[.NET] ขอโค๊ด สั่งปริ้นauto VB.net 2010 จากฟอร์ม ReportViewer ครับ

 
Topic : 119240



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



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



ขอโค๊ด สั่งปริ้นauto VB.net 2010 จากฟอร์ม ReportViewer ครับ
ตอนนี้ผมสามารถถึงข้อมูลลงในฟอร์ม ReportViewer แล้ว แต่ต้องการให้ปริ้นข้อมูลนั่นออกเลย จากปุ่มที่เราสร้างขึ้นเอง โดยที่ไม่ใช้ปุ่ม Print ที่ฟอร์ม ReportViewer ครับ

ขอบคุณครับ



Tag : .NET, VS 2010 (.NET 4.x)

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-10-07 10:07:22 By : Mos_Paper View : 2939 Reply : 1
 

 

No. 1



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



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


Code (VB.NET)
001.Imports System
002.Imports System.IO
003.Imports System.Data
004.Imports System.Text
005.Imports System.Drawing
006.Imports System.Drawing.Imaging
007.Imports System.Drawing.Printing
008.Imports System.Collections.Generic
009.Imports System.Windows.Forms
010.Imports Microsoft.Reporting.WinForms
011. 
012.Public Class Demo
013.    Implements IDisposable
014.    Private m_currentPageIndex As Integer
015.    Private m_streams As IList(Of Stream)
016. 
017.    Private Function LoadSalesData() As DataTable
018.        ' Create a new DataSet and read sales data file
019.        ' data.xml into the first DataTable.
020.        Dim dataSet As New DataSet()
021.        dataSet.ReadXml("..\..\data.xml")
022.        Return dataSet.Tables(0)
023.    End Function
024. 
025.    ' Routine to provide to the report renderer, in order to
026.    ' save an image for each page of the report.
027.    Private Function CreateStream(ByVal name As String, ByVal fileNameExtension As String, ByVal encoding As Encoding, ByVal mimeType As String, ByVal willSeek As Boolean) As Stream
028.        Dim stream As Stream = New MemoryStream()
029.        m_streams.Add(stream)
030.        Return stream
031.    End Function
032. 
033.    ' Export the given report as an EMF (Enhanced Metafile) file.
034.    Private Sub Export(ByVal report As LocalReport)
035.        Dim deviceInfo As String = "<DeviceInfo>" & _
036.            "<OutputFormat>EMF</OutputFormat>" & _
037.            "<PageWidth>8.5in</PageWidth>" & _
038.            "<PageHeight>11in</PageHeight>" & _
039.            "<MarginTop>0.25in</MarginTop>" & _
040.            "<MarginLeft>0.25in</MarginLeft>" & _
041.            "<MarginRight>0.25in</MarginRight>" & _
042.            "<MarginBottom>0.25in</MarginBottom>" & _
043.            "</DeviceInfo>"
044.        Dim warnings As Warning()
045.        m_streams = New List(Of Stream)()
046.        report.Render("Image", deviceInfo, AddressOf CreateStream, warnings)
047.        For Each stream As Stream In m_streams
048.            stream.Position = 0
049.        Next
050.    End Sub
051. 
052.    ' Handler for PrintPageEvents
053.    Private Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
054.        Dim pageImage As New Metafile(m_streams(m_currentPageIndex))
055. 
056.        ' Adjust rectangular area with printer margins.
057.        Dim adjustedRect As New Rectangle(ev.PageBounds.Left - CInt(ev.PageSettings.HardMarginX), _
058.                                          ev.PageBounds.Top - CInt(ev.PageSettings.HardMarginY), _
059.                                          ev.PageBounds.Width, _
060.                                          ev.PageBounds.Height)
061. 
062.        ' Draw a white background for the report
063.        ev.Graphics.FillRectangle(Brushes.White, adjustedRect)
064. 
065.        ' Draw the report content
066.        ev.Graphics.DrawImage(pageImage, adjustedRect)
067. 
068.        ' Prepare for the next page. Make sure we haven't hit the end.
069.        m_currentPageIndex += 1
070.        ev.HasMorePages = (m_currentPageIndex < m_streams.Count)
071.    End Sub
072. 
073.    Private Sub Print()
074.        If m_streams Is Nothing OrElse m_streams.Count = 0 Then
075.            Throw New Exception("Error: no stream to print.")
076.        End If
077.        Dim printDoc As New PrintDocument()
078.        If Not printDoc.PrinterSettings.IsValid Then
079.            Throw New Exception("Error: cannot find the default printer.")
080.        Else
081.            AddHandler printDoc.PrintPage, AddressOf PrintPage
082.            m_currentPageIndex = 0
083.            printDoc.Print()
084.        End If
085.    End Sub
086. 
087.    ' Create a local report for Report.rdlc, load the data,
088.    ' export the report to an .emf file, and print it.
089.    Private Sub Run()
090.        Dim report As New LocalReport()
091.        report.ReportPath = "..\..\Report.rdlc"
092.        report.DataSources.Add(New ReportDataSource("Sales", LoadSalesData()))
093.        Export(report)
094.        Print()
095.    End Sub
096. 
097.    Public Sub Dispose() Implements IDisposable.Dispose
098.        If m_streams IsNot Nothing Then
099.            For Each stream As Stream In m_streams
100.                stream.Close()
101.            Next
102.            m_streams = Nothing
103.        End If
104.    End Sub
105. 
106.    Public Shared Sub Main(ByVal args As String())
107.        Using demo As New Demo()
108.            demo.Run()
109.        End Using
110.    End Sub
111.End Class

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-10-07 14:13:04 By : Mos_Paper
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขอโค๊ด สั่งปริ้นauto VB.net 2010 จากฟอร์ม ReportViewer ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





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