如何实现 混打并且图像尽可能的清晰,位置相对固定!

解决方案 »

  1.   

    使用RDLC进行打印? 还是怎么
      

  2.   

    [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);
            ArrayList arry;
            ArrayList arry2;
            Bitmap memoryImage;
            private void Form1_Load(object sender, EventArgs e)
            {
                arry = new ArrayList();
                arry2 = new ArrayList();
                printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
                panel1.Paint += new PaintEventHandler(panel1_Paint);
            }        void panel1_Paint(object sender, PaintEventArgs e)
            {
                for (int i = 0; i < arry.Count; i++)
                {
                    e.Graphics.DrawImage(((Bitmap)arry[i]), ((Point)arry2[i]));
                }
            }        void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
            {            
                
                e.Graphics.DrawImage(memoryImage,0,0);
            }        /// <summary>
            /// 生成图像
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void button2_Click(object sender, EventArgs e)
            {
                Size s = panel1.Size;
                Graphics mygraphics;
                Graphics memoryGraphics;
                IntPtr dc1;
                IntPtr dc2;
                
                //为容器内的所有控件生成图像
                foreach (Control c in panel1.Controls)
                {                mygraphics = c.CreateGraphics();
                    s = c.Size;
                    memoryImage = new Bitmap(s.Width, s.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    memoryGraphics = Graphics.FromImage(memoryImage);
                    dc1 = mygraphics.GetHdc();
                    dc2 = memoryGraphics.GetHdc();
                    BitBlt(dc2, 0, 0, c.ClientRectangle.Width, c.ClientRectangle.Height, dc1, 0, 0, 13369376);
                    mygraphics.ReleaseHdc(dc1);
                    memoryGraphics.ReleaseHdc(dc2);
                    arry.Add(memoryImage);
                    Point p = new Point(c.Location.X,c.Location.Y);
                    arry2.Add(p);
                }
                this.Refresh();
                mygraphics = panel1.CreateGraphics();
                s = panel1.Size;
                memoryImage = new Bitmap(s.Width, s.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                memoryGraphics = Graphics.FromImage(memoryImage);
                dc1 = mygraphics.GetHdc();
                dc2 = memoryGraphics.GetHdc();
                BitBlt(dc2, 0, 0, panel1.ClientRectangle.Width, panel1.ClientRectangle.Height, dc1, 0, 0, 13369376);
                mygraphics.ReleaseHdc(dc1);
                memoryGraphics.ReleaseHdc(dc2);
            }        /// <summary>
            /// 打印预览
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void button3_Click(object sender, EventArgs e)
            {
                printPreviewDialog1.Document = this.printDocument1;
                printPreviewDialog1.Show();        }