疑问一:在下要打印的“Panel”控件的大小为:160*221的,但是当点击打印时弹出“打印预览窗口”。但是“Panel”的内容出现在“打印纸张”的左上角,很小一块。怎样,也就是修改这个打印类的参数可以让“Panel”的内容填满整个纸张界面?疑问二:这个截图打印类的实现思路是怎样的?
也就是怎样截的图?怎样打印的图?又怎样生成的打印预览界面,还有那么多的按钮?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;namespace tsleyyg.panelPrint
{
    class panelPrint
    {
        private static Bitmap mBitmap = null;
        private static System.Drawing.Printing.PrintDocument printDoc = new System.Drawing.Printing.PrintDocument();        public static void PrintPanel(Panel p)
        {
            PrintPreviewDialog ppvw;
            Graphics mygraphics = p.CreateGraphics();
            Size s = p.Size;
            mBitmap = new Bitmap(s.Width,s.Height,mygraphics);
            Graphics memoryGraphics = Graphics.FromImage(mBitmap);            IntPtr dc1 = mygraphics.GetHdc();
            IntPtr dc2 = memoryGraphics.GetHdc();            BitBlt(dc2,0,0,p.ClientRectangle.Width,p.ClientRectangle.Height,dc1,0,0,13369376);
            mygraphics.ReleaseHdc(dc1);
            memoryGraphics.ReleaseHdc(dc2);            ppvw = new PrintPreviewDialog();
            ppvw.Width = 160;
            ppvw.Height = 221;
            ppvw.Document = printDoc;
            printDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
            if (ppvw.ShowDialog() != DialogResult.OK)
            {
                printDoc.PrintPage -= new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
                return;
            }            printDoc.Print();
        }        [System.Runtime.InteropServices.DllImport("gdi32.dll")]
        private static extern long BitBlt(IntPtr HDest, int nXDest, int nYDest, int nWidth, int hHeight, IntPtr Hsrc, int nXSrc, int nYSrc, int DwRop);        private static void PrintDoc_PrintPage(Object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(mBitmap,0,0);
        }
    }
}