C# 惠普打印機 打印

打印機通用:

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)

        {

            Font font = new Font("宋體", 12);

            Brush bru = Brushes.Black;

            Image bitmap = new Bitmap(panel1.BackgroundImage.Width, panel1.BackgroundImage.Height);

            Graphics g = e.Graphics;  //先建立畫布  

            g.DrawImage(bitmap, 0, 0);

            int x = 0;//調整位置信息  

            int y = 0;

            foreach (Control item in panel1.Controls)

            {

                if (item is TextBox)

                {

                    Control tx = (item as Control);

                    g.DrawString(tx.Text, font, bru, tx.Left + x, tx.Top + y);

                }

                if (item is PictureEdit)

                {

                    Control tx = (item as Control);

                    e.Graphics.DrawImage(pictureEdit1.Image, tx.Left + x, tx.Top + y);

                }

            }

        }

        //打印

        private void simpleButton1_Click(object sender, EventArgs e)

        {

            PrintText();

            PrintDialog pdia = new PrintDialog();

            PrintDocument pdoc = new PrintDocument();             

            pdoc.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);

            if (pdia.ShowDialog() == DialogResult.OK)

            {

                pdoc.Print();

            }  

        }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章