C#打印窗体的一部分区域并控制打印的大小

C#打印窗体的部分区域并控制打印的大小
  CS的代码,需要答应窗体的一个区域,需要打印的部分我放在了一个panel里,只打印pannel里面的部分,其余区域不打印

 自己试了很多次,发现打印区域总是无法完全控制 请问有没有谁做过类似的例子 最好能给出代码

一下是我的代码
 

   private void btnPrint_Click(object sender, EventArgs e)
        {
            CaptureScreen();
            this.printPreviewDialog1.Width = this.panelPrint.Width;
            this.printPreviewDialog1.ShowDialog();
        }

        private void CaptureScreen()
        {
            int x = this.panelPrint.Location.X;
            int y = this.panelPrint.Location.Y;
            int dx = this.panelPrint.Location.X;
            int dy = this.panelPrint.Location.Y;
            int fx = this.Location.X;
            int fy = this.Location.Y;

            Graphics myGraphics = this.panelPrint.CreateGraphics();
            Size s = this.panelPrint.Size;
            memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
            Graphics memoryGraphics = Graphics.FromImage(memoryImage);
            memoryGraphics.CopyFromScreen(x,y,x,y,s);
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(memoryImage, this.panelPrint.Location.X, this.panelPrint.Location.Y);
        }

------解决方案--------------------
http://blog.****.net/liuweihuhao/article/details/5812690  试试
------解决方案--------------------
http://blog.****.net/chybaby/article/details/3167846

参考这里的SaveUserArea方法
------解决方案--------------------
直接用Bitmap将panel的内容绘制下来,然后打印Bitmap的内容


using System.Drawing.Printing;
Bitmap _NewBitmap = null;
        public void InitPrint()
        {
            _NewBitmap = new Bitmap(panel1.Width, panel1.Height);
            panel1.DrawToBitmap(_NewBitmap, new Rectangle(0, 0, _NewBitmap.Width, _NewBitmap.Height));
        }
        private void button1_Click(object sender, EventArgs e)
        {
            InitPrint();          
            StandardPrintController spc = new StandardPrintController();
            this.printDocument1.PrintController = spc;
            this.printDocument1.Print();
        }
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(_NewBitmap, 0, 0, _NewBitmap.Width, _NewBitmap.Height);
        }