zoukankan      html  css  js  c++  java
  • Graphics绘制类及打印机设置相关

    Graphics 有两个多个方法 这里面介绍3个:

      1.Graphics.drawString();绘制.画字符串...........                                    

        e.Graphics.DrawString("新乡市三月软件公司入库单", new Font(new FontFamily("黑体"), 11), System.Drawing.Brushes.Black, 170, 10);

                 e.Graphics.DrawString("供货商:河南科技学院", new Font(new FontFamily("黑体"), 8), System.Drawing.Brushes.Blue, 10, 12);

      2.Graphics.drawImage();绘制.画图像.............

        e.Graphics.DrawImage(pictureBox1.Image,e.Graphics.VisibleClipBounds);

      3.Graphics.drawLine();绘制.画线......................

        e.Graphics.DrawLine(Pens.Black, 8, 30, 480, 30); //pens.black 是用钢笔画

        Margins mgin = new Margins(50,50,50,50); //设置边距(上下左右)
        printDocument1.DefaultPageSettings.Margins = mgin;
        printDocument1.DefaultPageSettings.PaperSize = new PaperSize("A4",216,321); //设置纸张的大小单位为英寸

     private void button2_Click(object sender, EventArgs e)
            {
                PrintDialog printdialog = new PrintDialog();
                printdialog.Document = printDocument1;
                //Margins mgin = new Margins(50,50,50,50); //设置边距(上下左右)
                //printDocument1.DefaultPageSettings.Margins = mgin;
                printDocument1.DefaultPageSettings.PaperSize = new PaperSize("A4",216,321); //设置纸张的大小单位为英寸
                if (printdialog.ShowDialog()==DialogResult.OK)
                {
                    printDocument1.Print();
                }
            }
    
            private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
            {
                try{                                  
                     e.Graphics.DrawString("新乡市三月软件公司入库单", new Font(new FontFamily("黑体"), 11), System.Drawing.Brushes.Black, 170, 10);
                     e.Graphics.DrawString("供货商:河南科技学院", new Font(new FontFamily("黑体"), 8), System.Drawing.Brushes.Blue, 10, 12);
                     //信息的名称
                     e.Graphics.DrawLine(Pens.Black, 8, 30, 480, 30);
                     e.Graphics.DrawString("入库单编号", new Font(new FontFamily("黑体"), 8), System.Drawing.Brushes.Black, 9, 35);
                     e.Graphics.DrawString("商品名称", new Font(new FontFamily("黑体"), 8), System.Drawing.Brushes.Black, 160, 35);
                     e.Graphics.DrawString("数量", new Font(new FontFamily("黑体"), 8), System.Drawing.Brushes.Black, 260, 35);
                     e.Graphics.DrawString("单价", new Font(new FontFamily("黑体"), 8), System.Drawing.Brushes.Black, 330, 35);
                     e.Graphics.DrawString("总金额", new Font(new FontFamily("黑体"), 8), System.Drawing.Brushes.Black, 400, 35);
                     e.Graphics.DrawLine(Pens.Black, 8, 50, 480, 50);
                     //产品信息
                     e.Graphics.DrawString("R2011-01-2016:06:35", new Font(new FontFamily("黑体"), 8), System.Drawing.Brushes.Black, 9, 55);
                     e.Graphics.DrawString("联想A460", new Font(new FontFamily("黑体"), 8), System.Drawing.Brushes.Black, 160, 55);
                     e.Graphics.DrawString("100", new Font(new FontFamily("黑体"), 8), System.Drawing.Brushes.Black, 260, 55);
                     e.Graphics.DrawString("200.00", new Font(new FontFamily("黑体"), 8), System.Drawing.Brushes.Black, 330, 55);
                     e.Graphics.DrawString("20000.00", new Font(new FontFamily("黑体"), 8), System.Drawing.Brushes.Black, 400, 55);
    
    
                e.Graphics.DrawLine(Pens.Black, 8, 200, 480, 200);
                e.Graphics.DrawString("地址:新乡市河南科技学院信息工程学院", new Font(new FontFamily("黑体"), 8), System.Drawing.Brushes.Black, 9, 210);
                e.Graphics.DrawString("经办人:任忌", new Font(new FontFamily("黑体"), 8), System.Drawing.Brushes.Black, 220, 210);
                e.Graphics.DrawString("服务热线:15083128577", new Font(new FontFamily("黑体"), 8), System.Drawing.Brushes.Black, 320, 210);
                e.Graphics.DrawString("入库时间:" + DateTime.Now.ToString(), new Font(new FontFamily("黑体"), 8), System.Drawing.Brushes.Black, 9, 230);
                //{
                //    if (pictureBox1.Image!=null)
                //    {
                //        e.Graphics.DrawImage(pictureBox1.Image,e.Graphics.VisibleClipBounds);
                //        e.HasMorePages = false;
                //    }
                }
                catch (Exception ex)
                {
                    
                    
                }
    
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                PrintPreviewDialog my = new PrintPreviewDialog();
                my.Document = printDocument1;
               
                my.ShowDialog();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                textBox1.Focus();
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                PageSetupDialog mu = new PageSetupDialog();
                mu.Document = printDocument1;
                mu.ShowDialog();
                
            }
    

      

  • 相关阅读:
    day24<多线程>
    day23<File类递归练习>
    day22<IO流+>
    day21<IO流+&FIle递归>
    day20<IO流>
    day19<异常&File类>
    day18<集合框架+>
    day17<集合框架+>
    R语言中的标准输入,输出, 错误流
    Perl Spreadsheet::WriteExcel 模块自动生成excel 文件
  • 原文地址:https://www.cnblogs.com/xiaowie/p/8807425.html
Copyright © 2011-2022 走看看