c#打印预览窗体结果是一片空白
想实现打印窗体和窗体上的控件,参考了大家的代码,结果点击打印的时候,预览的结果是一边显示完了整个窗体,但是旁边多出了一块空白,请教各位这应该怎么解决呢。谢谢啊。
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;namespace ContractFill{ public partial class ZWebSite : Form { public ZWebSite(ContractFill.Main parent) { InitializeComponent(); this.MdiParent = parent; } private void button3_Click(object sender, EventArgs e) { Close(); } [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 Bitmap memoryImage; private void CaptureScreen() { Graphics mygraphics = this.CreateGraphics(); Size s = this.Size; memoryImage = new Bitmap(s.Width, s.Height, mygraphics); Graphics memoryGraphics = Graphics.FromImage(memoryImage); IntPtr dc1 = mygraphics.GetHdc(); IntPtr dc2 = memoryGraphics.GetHdc(); BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376); mygraphics.ReleaseHdc(dc1); memoryGraphics.ReleaseHdc(dc2); } private void button1_Click(object sender, EventArgs e) { CaptureScreen(); printPreviewDialog1.ShowDialog(); } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.Graphics.DrawImage(memoryImage, 0, 0); } }}