zoukankan      html  css  js  c++  java
  • winform 打印控件

    printDocument 设置打印对象的各项初始属性,需要首先设置,面向对象的操作

    打印控件分三步

    1、打印页面设置 pageSetupDialog

    2、打印预览 printPreviewControl  打印预览控件,不经常用

                       printPreviewDialog  打印预览对话框,常用

    3、打印       printDialog

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace dayyin
    {
        public partial class Form1 : Form
        {
            //打印步骤
         
            //打印设置
            //打印预览
            //打印
            public Form1()
            {
                InitializeComponent();
            }
    
            private void 页面设置ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                pageSetupDialog1.Document = printDocument1;//将打印设置的指向打印对象1
                pageSetupDialog1.ShowDialog();//弹出打印设置对话框
            }
    
            private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
            {
                //首先要设置打印对象,类似于画板
                Font f=new Font("宋体",14);//设置字体
                Brush b=new SolidBrush(Color.Black);//设置画刷样式
                PointF p = new PointF(10,10);//定义坐标点
                e.Graphics.DrawString(textBox1.Text,f,b,p);//设置绘画参数,要绘制的字符串,字体,格式刷,坐标
                //System.Drawing.Printing 命名空间提供与打印相关的服务。
                //PrintPageEventArgs为 PrintPage 事件提供数据。
                //Graphics 图形,图形,显卡
                //DrawString 绘制字符串形式
            }
    
            private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
            {
    
            }
    
            private void 打印预览VToolStripMenuItem_Click(object sender, EventArgs e)
            {
                //printPreviewControl1.Document = printDocument1;//打印预览控件
                printPreviewDialog1.Document = printDocument1;//打印对话框
                printPreviewDialog1.ShowDialog();
            }
    
            private void 打印PToolStripMenuItem_Click(object sender, EventArgs e)
            {
                printDialog1.Document = printDocument1;//指向打印内容
                printDialog1.ShowDialog();//显示打印对话框
            }
    
    
    
        }
    }

  • 相关阅读:
    linq获取最大ID值
    asp:MultiView选项卡控件,可以用来选择性的显示需要的部门
    TFS修改工作区映射区
    怎么解决javascript小数相减会出现一长串的小数位数?
    (转)向页面动态载入用户控件和自定义控件的方法(谨记)
    (转)工作经验到底是个什么东东?工作经验从哪里来?
    hdu 5441 travel 离线+带权并查集
    hdu 5438 Ponds dfs
    hdu 5437 Alisha’s Party 模拟 优先队列
    CF 500 B. New Year Permutation 并查集
  • 原文地址:https://www.cnblogs.com/fengsantianya/p/5631416.html
Copyright © 2011-2022 走看看