Встала задача распечатать данные из DataGrid (по возможности в табличном виде и строго без применения CrystalReport).
Не киньте ли идейку (уж о коде в качестве примера молчу!) как это реализовать.
Поиск не помог, в инете не нашел.
Private Declare Function PrintWindow Lib "user32.dll" (ByVal _
hwnd As IntPtr, ByVal hdcBlt As IntPtr, ByVal nFlags As _
UInt32) As Boolean
Dim screenGrab As Bitmap
Private Sub CaptureScreen()
screenGrab = New Bitmap(Me.Width, Me.Height)
Dim g As Graphics = Graphics.FromImage(screenGrab)
Dim hdc As IntPtr = g.GetHdc
Form1.PrintWindow(Me.Handle, hdc, Nothing)
g.ReleaseHdc(hdc)
g.Flush()
g.Dispose()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
PrintDocument1.PrintPage
Dim pagewidth As Single = e.PageBounds.Width / 100
Dim pageheight As Single = e.PageBounds.Height / 100
Dim pagewidthpixels As Integer = pagewidth * e.PageSettings.PrinterResolution.X
Dim pageheightpixels As Integer = pageheight * e.PageSettings.PrinterResolution.Y
Dim width_ratio As Double = pagewidthpixels / screenGrab.Width
Dim height_ratio As Double = pageheightpixels / screenGrab.Height
Dim scaling_factor As Double
If width_ratio > height_ratio Then
scaling_factor = height_ratio
Else
scaling_factor = width_ratio
End If
screenGrab.SetResolution(e.PageSettings.PrinterResolution.X / scaling_factor, e.PageSettings.PrinterResolution.Y / scaling_factor)
e.Graphics.DrawImage(screenGrab, 0, 0)
End Sub
Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button6.Click
CaptureScreen()
PrintDocument1.DefaultPageSettings.Landscape = screenGrab.Width > screenGrab.Height
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
End Sub
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 39