• 测试打印功能


    // 先创建窗体,后拉入Button控件两个,一个预览功能,一个打印功能,再拉入控件PrintDocument控件、PrintPreviewDilogs控件、pageSetupDilogs控件

    // 后台代码

     1 List<string> students = new List<string>() {"张三","李四","王五" };
     2         int count = 0;//要打印的学员姓名的下标值
     3         private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
     4         {
     5             Graphics g = e.Graphics;
     6             string name = students[count];
     7             g.DrawString(name,new Font("宋体",20),Brushes.Black,100,100);
     8             //g.DrawLine(new Pen(Color.Red),new Point(200,200),new Point(300,200));
     9             g.Dispose();
    10             count++;//递增,为了打印下一个姓名
    11             //判断打印是否结束
    12             if (count == students.Count)
    13             {
    14                 e.HasMorePages = false;//不会打印下一页
    15             }
    16             else
    17             {
    18                 e.HasMorePages = true;//继续打印下一页
    19             }
    20         }
    21 
    22         //预览按钮
    23         private void btnPrev_Click(object sender, EventArgs e)
    24         {
    25             this.printPreviewDialog1.Document = this.printDocument1;
    26             this.printPreviewDialog1.ShowDialog();
    27         }
    28 
    29         // 打印按钮
    30         private void btnPrint_Click(object sender, EventArgs e)
    31         {
    32             this.pageSetupDialog1.Document = this.printDocument1;
    33             if(this.pageSetupDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
    34             {
    35                 this.printDocument1.Print();//打印
    36             }
    37         }
  • 相关阅读:
    关于Manjaro+kde桌面Tim闪退的解决
    Manjaro-kde-18.1.3安装体验
    Ubuntu19.10安装
    OPPO R11刷机初体验
    Microsoft store应用商店打不开0x80131500
    提问回顾与个人总结
    OO第三单元总结
    OO第二单元总结
    软工案例分析作业
    OO第一单元总结
  • 原文地址:https://www.cnblogs.com/xjx8205/p/4696910.html
Copyright © 2020-2023  润新知