【求助】如何打印DataGridView控件中显示的内容
如何打印DataGridView控件中显示的内容,各位大虾有没有源代码示例一下! --------------------编程问答-------------------- up --------------------编程问答-------------------- up --------------------编程问答-------------------- 据我知道是截屏打印,在此把必要的代码附上。需要从工具箱中添加PringDocument在这里命名为pdusing System.Drawing.Printing;
public partial class I03_01 : Baosight.iSuperFrame.Forms.FormBase
{
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private void CaptureForm()
{
Graphics MyGraphics = this.CreateGraphics();
Size s = this.Size; //在这里自己根据需要调节打印的区域
s.Height = flexgrid.Bounds.Y + flexgrid.Height;
Image MyImage = new Bitmap(s.Width, s.Height, MyGraphics);
Graphics memoryGraphics = Graphics.FromImage(MyImage);
IntPtr dc1 = MyGraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, s.Width, s.Height, dc1, 0, 0, 13369376);
MyGraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
MyImage.Save(@"C:\Capture.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
private void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.HasMorePages = false;
e.Graphics.DrawImage(Image.FromFile(@"C:\Capture.jpg"), e.Graphics.VisibleClipBounds);
}
private void btnPrint_Click(object sender, EventArgs e)
{
CaptureForm();
pd.DefaultPageSettings.Landscape = true;
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
pd.Print();
}
补充:.NET技术 , C#