winform 打印panel的内容不完整

wudi1027 2013-01-11 08:52:31
只有当前画面的内容,滚动条下面的内容不能打印出来,何解?


使用了ControlPrint组件,但是打印的图小了,如何调大点。
...全文
396 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yalan 2013-01-12
  • 打赏
  • 举报
回复
附我的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Text;
using System.Windows.Forms;

namespace njtnpgd
{
    public partial class frm_print : Form
    {
        Form1 f1 = new Form1();
        public frm_print(Form1 _f1)
        {
            f1 = _f1;
            InitializeComponent();
        }

        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
        private static extern bool BitBlt(
        IntPtr hdcDest, // handle to destination DC
        int nXDest, // x-coord of destination upper-left corner
        int nYDest, // y-coord of destination upper-left corner
        int nWidth, // width of destination rectangle
        int nHeight, // height of destination rectangle
        IntPtr hdcSrc, // handle to source DC
        int nXSrc, // x-coordinate of source upper-left corner
        int nYSrc, // y-coordinate of source upper-left corner
        System.Int32 dwRop // raster operation code
        );
        Bitmap memoryImage = null;


        private void frm_print_Load(object sender, EventArgs e)
        {
            //测试不成功,注视掉,只能打印一个工单
            //if (f1.dataGridView1.SelectedRows.Count > 1)
            //{
            //    for (int i = 0; i < f1.dataGridView1.SelectedRows.Count; i++)
            //    {
            //        this.panelc.Height = this.panel1.Height*(i+1);
            //        Panel paneli=new Panel();
            //        paneli.BackColor = System.Drawing.Color.White;
            //        paneli.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            //        paneli.BackgroundImage = global::njtnpgd.Properties.Resources.pgd_table;
            //        paneli.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            //        paneli.Width = panel1.Width;
            //        paneli.Height = panel1.Height;
            //        paneli.Left = panel1.Left;
            //        paneli.Top = panel1.Top + panel1.Height*(i+1);

            //        //绘制单号
            //        TextBox tb_uid = new TextBox();
            //        tb_uid.BorderStyle = BorderStyle.None;
            //        tb_uid.Text = f1.dataGridView1.SelectedRows[i].Cells["pgdid"].Value.ToString();
            //        tb_uid.Width = 242; tb_uid.Height = 14; tb_uid.Left = paneli.Left + 87; tb_uid.Top = paneli.Top + 69;

            //        //绘制申报日期
            //        TextBox tb_pgd_addtime = new TextBox();
            //        tb_pgd_addtime.BorderStyle = BorderStyle.None;
            //        tb_pgd_addtime.Text = f1.dataGridView1.SelectedRows[i].Cells["pgd_addtime"].Value.ToString();
            //        tb_pgd_addtime.Width = 235; tb_pgd_addtime.Height = 14; tb_pgd_addtime.Left = paneli.Left + 433; tb_pgd_addtime.Top = paneli.Top + 69;

            //        //绘制用户姓名控件
            //        TextBox tb_uname = new TextBox();
            //        tb_uname.BorderStyle = BorderStyle.None;
            //        tb_uname.Text = f1.dataGridView1.SelectedRows[i].Cells["uname"].Value.ToString();
            //        tb_uname.Width = 92; tb_uname.Height = 14; tb_uname.Left = paneli.Left + 93; tb_uname.Top = paneli.Top + 101;

            //        //绘制用户联系电话控件
            //        TextBox tb_umobile = new TextBox();
            //        tb_umobile.BorderStyle = BorderStyle.None;
            //        tb_umobile.Text = f1.dataGridView1.SelectedRows[i].Cells["umobile"].Value.ToString();
            //        tb_umobile.Width = 93; tb_umobile.Height = 14; tb_umobile.Left = paneli.Left + 267; tb_umobile.Top = paneli.Top + 101;

            //        //绘制施工内容控件
            //        TextBox tb_proctype = new TextBox();
            //        tb_proctype.BorderStyle = BorderStyle.None;
            //        tb_proctype.Text = f1.dataGridView1.SelectedRows[i].Cells["pgdtype"].Value.ToString();
            //        tb_proctype.Width = 211; tb_proctype.Height = 14; tb_proctype.Left = paneli.Left + 443; tb_proctype.Top = paneli.Top + 101;

            //        //绘制用户住址控件
            //        TextBox tb_uaddress = new TextBox();
            //        tb_uaddress.BorderStyle = BorderStyle.None;
            //        tb_uaddress.Text = f1.dataGridView1.SelectedRows[i].Cells["uaddress"].Value.ToString();
            //        tb_uaddress.Width = 576; tb_uaddress.Height = 14; tb_uaddress.Left = paneli.Left + 93; tb_uaddress.Top = paneli.Top + 140;


            //        panelc.Controls.Add(tb_uid);
            //        panelc.Controls.Add(tb_pgd_addtime);
            //        panelc.Controls.Add(tb_uname);
            //        panelc.Controls.Add(tb_umobile);
            //        panelc.Controls.Add(tb_proctype);
            //        panelc.Controls.Add(tb_uaddress);
            //        this.panelc.Controls.Add(paneli);
            //    }
            //}

            //为控件赋值
            if (f1.dataGridView1.SelectedRows.Count > 1)
            {
                MessageBox.Show("出错了!每次只能打印一个工单", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
            else
            {
                try
                {
                    tb_uid.Text = f1.dataGridView1.SelectedRows[0].Cells["pgdid"].Value.ToString();
                    tb_pgd_addtime.Text = f1.dataGridView1.SelectedRows[0].Cells["pgd_addtime"].Value.ToString();
                    tb_uname.Text = f1.dataGridView1.SelectedRows[0].Cells["uname"].Value.ToString();
                    tb_umobile.Text = f1.dataGridView1.SelectedRows[0].Cells["umobile"].Value.ToString();
                    tb_proctype.Text = f1.dataGridView1.SelectedRows[0].Cells["pgdtype"].Value.ToString();
                    tb_uaddress.Text = f1.dataGridView1.SelectedRows[0].Cells["uaddress"].Value.ToString();
                    tb_pdr.Text = f1.dataGridView1.SelectedRows[0].Cells["pdr"].Value.ToString();
                    tb_sgry.Text = f1.dataGridView1.SelectedRows[0].Cells["shigongrenyuan"].Value.ToString();
                    tb_paidanshijian.Text = f1.dataGridView1.SelectedRows[0].Cells["paidanshijian"].Value.ToString();
                }
                catch
                {
                    MessageBox.Show("出错了!请联系技术部处理该错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                }
            }
        }



        private void pd_PrintPage(object sender, PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(memoryImage, 10, 30);
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            Graphics graphic = panelc.CreateGraphics();
            Size s = panelc.Size;
            Bitmap 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, panelc.ClientRectangle.Width, panelc.ClientRectangle.Height,dc1, 0, 0, 13369376);
            memoryImage = (Bitmap)memImage.Clone();
            graphic.ReleaseHdc(dc1);
            memGraphic.ReleaseHdc(dc2);
            graphic.Dispose();
            memGraphic.Dispose();
            memImage.Dispose();

            PrintPreviewDialog dlg = new PrintPreviewDialog();
            PrintDocument pd = new PrintDocument();
            pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
            pd.Print();
        }

        private void toolStrip1_MouseEnter(object sender, EventArgs e)
        {
            label1.Focus();
        }


    }
}

yalan 2013-01-12
  • 打赏
  • 举报
回复
同问,我也有这个问题,打印的时候只能打印panel显示出来的内容,滚动条外面的内容无法打印出来。 因为Panel内的内容都是自动生成的,所以Panel可能很长,因此需要能够打印整个panel的方法。自己琢磨了一天了,无解,期待大神能帮助。
zfjclark 2013-01-11
  • 打赏
  • 举报
回复
预览时能看到就能打印出来,打印机只会打印一个界面,隐藏的东西肯定不行啊,你把东西做小点,都放到一个界面下就行吧
熙风 2013-01-11
  • 打赏
  • 举报
回复
敢问你怎么打印的?

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧