怎样才能打印出Panel中的所有内容,包括Lable和PictureBox控件
下面是我的代码
[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 Bitmap memImage;
        public void Print(object sender,PrintPageEventArgs e)
        {
            Graphics graphic = framework.pnlframework1.CreateGraphics();
            Size s = framework.pnlframework1.Size;
            memImage = new Bitmap(s.Width, s.Height, graphic);
            Graphics memGraphic = Graphics.FromImage(memImage);
            IntPtr dc1 = graphic.GetHdc();
            IntPtr dc2 = memGraphic.GetHdc();            BitBlt(dc2, 0, 0, framework.pnlframework1.ClientRectangle.Width, framework.pnlframework1.ClientRectangle.Height, dc1, 0, 0, 13369376);            //Clone       the   bitmap   so   we   can   dispose   it.     
            Image print_image = (Image)memImage.Clone();
            graphic.ReleaseHdc(dc1);
            memGraphic.ReleaseHdc(dc2);
            memGraphic.Dispose();
            memImage.Dispose();
        }private void document_PrintPage(object sender, PrintPageEventArgs e)

            e.Graphics.DrawImage(memImage, 0, 0);
}
出现参数无效,怎样修改?各位高手帮帮忙

解决方案 »

  1.   

    控件有个方法
    Control.DrawToBitmap(参数);然后打印图片可否
      

  2.   

        Bitmap _Bitmap = new Bitmap(Panel1.Width, Panel1.Height);            Panel1.DrawToBitmap(_Bitmap, new Rectangle(0, 0, _Bitmap.Width, _Bitmap.Height));
      

  3.   

    Panel中的内容太多,用滚动条才能浏览,这样如何打印所有的内容
      

  4.   

    Panel中嵌套Panel,
    外面的用来显示滚动条,里面的用来输出图像和打印
      

  5.   

    怎把panel 中的值全部打印出来
      

  6.   

     private Bitmap memImage = null;//声明全局变量 下面代码会用到的
            //打印
            private void vistaButton1_Click(object sender, EventArgs e)
            {
                //PrintDocument pd = new PrintDocument();
                //pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
                //PrintPreviewDialog cppd = new PrintPreviewDialog();
                //cppd.Document = pd;
                //cppd.ShowDialog();
                Graphics graphic = panel1.CreateGraphics();
                Size s = panel1.Size;
                memImage = new Bitmap(s.Width, s.Height, graphic);
                Graphics memGraphic = Graphics.FromImage(memImage);
                IntPtr dc1 = graphic.GetHdc();
                IntPtr dc2 = memGraphic.GetHdc();            BitBlt(dc2, 0, 0, panel1.ClientRectangle.Width, panel1.ClientRectangle.Height,
                      dc1, 0, 0, 13369376);            //Clone       the   bitmap   so   we   can   dispose   it.     
                Image print_image = (Image)memImage.Clone();
                graphic.ReleaseHdc(dc1);
                memGraphic.ReleaseHdc(dc2);
                graphic.Dispose();
                memGraphic.Dispose();
                //memImage.Dispose();            PrintPreviewDialog dlg = new PrintPreviewDialog();
                dlg.Width = 1100;
                dlg.Height = 500;
                dlg.Document = printDocument1;            if (dlg.ShowDialog() == DialogResult.OK)
                    printDocument1.Print();  
      
            }
            //[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 Bitmap memoryImage;
            //private void CaptureScreen()
            //{
            //    Graphics mygraphics = this.panel1.CreateGraphics();//绘制Panel图像
            //    Size s = this.panel1.Size;//取Panel的大小
            //    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.panel1.ClientRectangle.Width, this.panel1.ClientRectangle.Height, dc1, 0, 0, 13369376);
            //    mygraphics.ReleaseHdc(dc1);
            //    memoryGraphics.ReleaseHdc(dc2);
            //}
            [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]//应用API函数
            private static extern bool BitBlt(
            IntPtr hdcDest, // 目标设备的句柄 
            int nXDest, // 目标对象的左上角的X坐标 
            int nYDest, // 目标对象的左上角的X坐标 
            int nWidth, // 目标对象的矩形的宽度 
            int nHeight, // 目标对象的矩形的长度 
            IntPtr hdcSrc, // 源设备的句柄 
            int nXSrc, // 源对象的左上角的X坐标 
            int nYSrc, // 源对象的左上角的X坐标 
            System.Int32 dwRop // 光栅的操作值 
            );        void pd_PrintPage(object sender, PrintPageEventArgs e)
            {
                //Graphics g = e.Graphics;
                //BarcodeControl dd = new BarcodeControl();            //Rectangle rect = dd.ClientRectangle;
                ////打印
                //dd.Draw(g, rect, GraphicsUnit.Inch, 0.01f, 0, null);
                //g.Dispose();
                //只打印图像
                e.Graphics.DrawImage(memImage, 0, 0);
            }
            //预览
            int mm;
            private void button2_Click(object sender, EventArgs e)
            {
                #region //打印预览
                string sqlstr = "select Count(distinct PartID) from L_Craft where MouldID='" +
                               txtMid.Text.Trim().ToString() + "'";
                int num = MRP.DBHelper.GetScalar(sqlstr);            string[] part = new string[num];
                ////查询零件号 
                string sql = "select distinct mould_m from L_Craft where  MouldID='" +
                    txtMid.Text.Trim().ToString() + "'";            SqlDataReader reader = MRP.DBHelper.GetReader(sql);
                int t = 0;
                while (reader.Read())
                {
                    part[t++] = reader[0].ToString();
                }
                for (int i = 0; i < num; i++)
                {
                    #region   1种方法
                    BarcodeControl dd = new BarcodeControl();
                     //dd.Size = new Size(160, 50);
                     //dd.Location = new Point((i % 3) * 160 + 100, i / 3 * 100);
                    //dd.CopyRight = "Imold条码";  //标题
                    dd.Data = part[i];  // 条形码取的数据
                    dd.BarcodeType=BarcodeType.CODE128B; //条形码类型                dd.Size = new Size(300, 90);
                    dd.Location = new Point((i % 3) * 280 +50, (i / 3) * 120);
                    this.panel1.Controls.Add(dd);
                    #endregion
                } 
                #endregion 
            }
             private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
            {
              
                e.Graphics.DrawImage(memImage,0,0);
            }这样打印,打印的只是本页的内容,怎么才能打印全部的呢,就是panel 滚动条下面的数据
      

  7.   


    这样打印,打印的只是本页的内容,怎么才能打印全部的呢,就是panel 滚动条下面的数据
     
     
     
     
      

  8.   

    不用panel自带的滚动条,设置panel.autosize=true,使用窗体或自己添加滚动条显示panel内容。
    然后使用Panel1.DrawToBitmap()输出。