PDA

View Full Version : چاپ DataGridView در vb.net



xxman1363
یک شنبه 23 دی 1386, 14:04 عصر
یه کد برای چاپ دیتا گرید می خوام

mpg_of_shb
یک شنبه 23 دی 1386, 18:25 عصر
کتاب vb.net کوروش مقدسی رو استفاده کن

saman_itc
دوشنبه 24 دی 1386, 12:56 عصر
چاپ فرم برات مزارم کدشو .چاپ DataGridView هست تو سایت بگرد عزیزم
اگه خواستی بگو مثال اجرایشو بزارم




form print

Imports System.Drawing.Imaging
Imports System.Drawing.Printing
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents PrintDocument1 As System.Drawing.Printing.PrintDocument
Friend WithEvents PageSetupDialog1 As System.Windows.Forms.PageSetupDialog
Friend WithEvents PrintPreviewControl1 As System.Windows.Forms.PrintPreviewControl
Friend WithEvents PrintPreviewDialog1 As System.Windows.Forms.PrintPreviewDialog
Friend WithEvents PrintDialog1 As System.Windows.Forms.PrintDialog
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents btnPrint As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(Get Type(Form1))
Me.Label1 = New System.Windows.Forms.Label
Me.btnPrint = New System.Windows.Forms.Button
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.Button1 = New System.Windows.Forms.Button
Me.PrintDocument1 = New System.Drawing.Printing.PrintDocument
Me.PageSetupDialog1 = New System.Windows.Forms.PageSetupDialog
Me.PrintPreviewControl1 = New System.Windows.Forms.PrintPreviewControl
Me.PrintPreviewDialog1 = New System.Windows.Forms.PrintPreviewDialog
Me.PrintDialog1 = New System.Windows.Forms.PrintDialog
Me.Button2 = New System.Windows.Forms.Button
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginIni t()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Comic Sans MS", 20.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(0, 0)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(408, 80)
Me.Label1.TabIndex = 0
Me.Label1.Text = "The quick brown fox jumps over the lazy dog."
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'btnPrint
'
Me.btnPrint.Anchor = System.Windows.Forms.AnchorStyles.Top
Me.btnPrint.Location = New System.Drawing.Point(184, 320)
Me.btnPrint.Name = "btnPrint"
Me.btnPrint.Size = New System.Drawing.Size(48, 24)
Me.btnPrint.TabIndex = 1
Me.btnPrint.Text = "Print"
'
'PictureBox1
'
Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
Me.PictureBox1.Location = New System.Drawing.Point(-249, 113)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(412, 270)
Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
Me.PictureBox1.TabIndex = 4
Me.PictureBox1.TabStop = False
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(260, 148)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 5
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleBackColor = True
'
'PrintDocument1
'
'
'PrintPreviewControl1
'
Me.PrintPreviewControl1.Location = New System.Drawing.Point(244, 203)
Me.PrintPreviewControl1.Name = "PrintPreviewControl1"
Me.PrintPreviewControl1.Size = New System.Drawing.Size(100, 100)
Me.PrintPreviewControl1.TabIndex = 6
'
'PrintPreviewDialog1
'
Me.PrintPreviewDialog1.AutoScrollMargin = New System.Drawing.Size(0, 0)
Me.PrintPreviewDialog1.AutoScrollMinSize = New System.Drawing.Size(0, 0)
Me.PrintPreviewDialog1.ClientSize = New System.Drawing.Size(400, 300)
Me.PrintPreviewDialog1.Document = Me.PrintDocument1
Me.PrintPreviewDialog1.Enabled = True
Me.PrintPreviewDialog1.Icon = CType(resources.GetObject("PrintPreviewDialog1.Icon"), System.Drawing.Icon)
Me.PrintPreviewDialog1.Name = "PrintPreviewDialog1"
Me.PrintPreviewDialog1.Visible = False
'
'PrintDialog1
'
Me.PrintDialog1.UseEXDialog = True
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(278, 113)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(75, 23)
Me.Button2.TabIndex = 7
Me.Button2.Text = "Button2"
Me.Button2.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(408, 349)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.PrintPreviewControl1)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.btnPrint)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.PictureBox1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n
Me.Text = "Form1"
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit( )
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
Private Declare Auto Function BitBlt Lib "gdi32.dll" (ByVal hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As System.Int32) As Boolean
Private Const SRCCOPY As Integer = &HCC0020
Private Declare Auto Function GetWindowDC Lib "user32" Alias "GetWindowDC" (ByVal hwnd As System.IntPtr) As System.IntPtr
' Get an image of the form plus its decoration
' (borders, title bar, etc).
Private Function GetDecoratedFormImage() As Bitmap
' Get this form's Graphics object.
Dim me_gr As Graphics = Me.CreateGraphics
' Make a Bitmap to hold the image.
Dim bm As New Bitmap(Me.Width, Me.Height, me_gr)
Dim bm_gr As Graphics = Graphics.FromImage(bm)
Dim bm_hdc As IntPtr = bm_gr.GetHdc
' Get the form's hDC. We must do this after
' creating the new Bitmap, which uses me_gr.
Dim me_hdc As IntPtr = GetWindowDC(Me.Handle)
' BitBlt the form's image onto the Bitmap.
BitBlt(bm_hdc, 0, 0, Me.Width, Me.Height, _
me_hdc, 0, 0, SRCCOPY)
bm_gr.ReleaseHdc(bm_hdc)
' Return the result.
Return bm
End Function
' Variables used to print.
Private m_PrintBitmap As Bitmap
' Private WithEvents m_PrintDocument As PrintDocument
'Private WithEvents PrintDocument1 As PrintDocument

' Print the picture.
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
' Copy the form's image into a bitmap.
m_PrintBitmap = GetDecoratedFormImage()

' Make a PrintDocument and print.
'm_PrintDocument = New PrintDocument
PrintDocument1 = New PrintDocument
'm_PrintDocument.Print()
PrintDocument1.Print()
End Sub
' Print the form image.
' Private Sub m_PrintDocument_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles m_PrintDocument.PrintPage
'' Draw the image centered.
'Dim x As Integer = e.MarginBounds.X + (e.MarginBounds.Width - m_PrintBitmap.Width) \ 2
'Dim y As Integer = e.MarginBounds.Y + (e.MarginBounds.Height - m_PrintBitmap.Height) \ 2
'e.Graphics.DrawImage(m_PrintBitmap, 1, 1)
'' Me.Text = (x).ToString + "x---y" + y.ToString
'' There's only one page.
'e.HasMorePages = False
' End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With PageSetupDialog1
.PageSettings = PrintDocument1.DefaultPageSettings
End With
Try
If PageSetupDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
End If
Catch es As Exception
MessageBox.Show(es.Message)
End Try
'PrintPreviewDialog1.Document = PrintDocument1
'PrintPreviewControl1.Document = PrintDocument1
'PrintPreviewDialog1.Document = PrintPreviewControl1.Document
'PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
' Draw the image centered.
Dim x As Integer = e.MarginBounds.X + (e.MarginBounds.Width - m_PrintBitmap.Width) \ 2
Dim y As Integer = e.MarginBounds.Y + (e.MarginBounds.Height - m_PrintBitmap.Height) \ 2
'e.Graphics.DrawImage(m_PrintBitmap, x, y)
e.Graphics.DrawImage(m_PrintBitmap, 0, 0)
' Me.Text = (x).ToString + "x---y" + y.ToString
' There's only one page.
e.HasMorePages = False
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
m_PrintBitmap = GetDecoratedFormImage()

' Make a PrintDocument and print.
PrintDocument1 = New PrintDocument
Try
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
Catch es As Exception
MessageBox.Show(es.Message)
End Try
End Sub
End Class

arsalansalar
دوشنبه 24 دی 1386, 14:03 عصر
دوست عزیز ممنون می شوم اگر یک sample هم بدهی.

saman_itc
دوشنبه 24 دی 1386, 16:33 عصر
اینم مثال حالشو ببر:قلب:

alih988
سه شنبه 25 دی 1386, 14:52 عصر
آقا سامان ، اینکه طریقه چاپ عکس بود ، در مورد چاپ دیتا گرید توضیح بدید ، مثلا کلیه محتویات یک دیتا گرید در یک ریپورت به صورت خودکار صفحه بنده بشه !

در واقع چاپ یک دیتاست در یک ریپورت!

khz-web1
یک شنبه 19 اسفند 1386, 12:33 عصر
خوب یک کریستال ریپورت ایجاد کن که داده هاشو از دیتا ستت بگیره !!!!