C#打印-全部打印源码


C#打印实例-全部打印源码实例
资源截图
代码片段和文件信息
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;
using System.Data.SqlClient;
using System.Collections;

namespace AllPrint
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        #region 定义全局对象及变量
        int intPage = 0;//总页数
        int intRows = 30;//每页行数
        int EndRows = 0;//最后一页函数
        int currentpageindex = 1;//当前打印页
        Pen myPen = new Pen(Color.Black);
        Font myFont = new Font(“宋体“ 9);//字体
        Brush myBrush = new SolidBrush(Color.Black);//画刷
        int PrintPageHeight = 1169;//打印的默认高度
        int PrintPageWidth = 827;//打印的默认宽度
        int topmargin = 60; //顶边距 
        int rowgap = 32;//行高 
        int leftmargin = 50;//左边距 
        int rightmargin = 50;//左边距
        int buttommargin = 80;//底边距 
        int columnWidth1 = 57;//第一列宽度
        int columnWidth2 = 335;//第二列宽度
        #endregion

        //加载数据
        private void Form1_Load(object sender EventArgs e)
        {
            SqlConnection sqlcon = new SqlConnection(“Data Source=.;Database=db_04;Uid=sa;Pwd=1;“);
            SqlDataAdapter sqlda = new SqlDataAdapter(“select IDNameSex   from tb_Student“ sqlcon);
            DataSet myds = new DataSet();
            sqlda.Fill(myds);
            dataGridView1.DataSource = myds.Tables[0];
            EndRows = (dataGridView1.Rows.Count-2) % intRows;//去掉标题和最后一行的空行
            if (EndRows > 0)
                intPage = Convert.ToInt32((dataGridView1.Rows.Count - 2) / intRows) + 1;
            else
                intPage = Convert.ToInt32((dataGridView1.Rows.Count - 2) / intRows);
            label1.Text = “共有“ + (dataGridView1.Rows.Count - 2) + “条数据  共“ + intPage + “页“;
        }

        //打印
        private void button2_Click(object sender EventArgs e)
        {
            printPreviewDialog1.ShowDialog();
        }

        //对打印文档进行设置
        private void printDocument1_PrintPage(object sender System.Drawing.Printing.PrintPageEventArgs e)
        {
            if (dataGridView1.Rows.Count > 0)
            {
                PrintPageWidth = e.PageBounds.Width;//获取打印线张的宽度
                PrintPageHeight = e.PageBounds.Height;//获取打印线张的高度

                #region 绘制边框线
                e.Graphics.DrawLine(myPen leftmargin topmargin PrintPageWidth - leftmargin - rightmargin topmargin);
                e.Graphics.DrawLine(myPen leftmargin topmargin leftmargin PrintPageHeight - topmargin - buttommargin);
                e.Graphics.DrawLine(myPen leftmargin PrintPageHeight - topmargin - buttommargin PrintPageWidth - leftmargin - rightmargin PrintPageHeight - topmargin - buttommargin);
                e.Graphics.DrawLine(myPen PrintPageWidth - leftmargin - rightmargin topmargin PrintPageWidth - leftmargin - rightma

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4081  2019-02-22 12:16  C#打印实例-全部打印源码实例AllPrintAllPrint.csproj

     文件      24064  2019-02-22 12:25  C#打印实例-全部打印源码实例AllPrintinDebugAllPrint.exe

     文件      34304  2019-02-22 12:25  C#打印实例-全部打印源码实例AllPrintinDebugAllPrint.pdb

     文件      11608  2019-02-22 12:25  C#打印实例-全部打印源码实例AllPrintinDebugAllPrint.vshost.exe

     文件        490  2013-03-18 17:00  C#打印实例-全部打印源码实例AllPrintinDebugAllPrint.vshost.exe.manifest

     文件       5476  2019-02-22 12:25  C#打印实例-全部打印源码实例AllPrintForm1.cs

     文件       6523  2019-02-22 12:25  C#打印实例-全部打印源码实例AllPrintForm1.designer.cs

     文件      21736  2019-02-22 12:25  C#打印实例-全部打印源码实例AllPrintForm1.resx

     文件       1840  2019-02-22 12:25  C#打印实例-全部打印源码实例AllPrintobjDebugAllPrint.csproj.FileListAbsolute.txt

     文件        847  2019-02-22 12:25  C#打印实例-全部打印源码实例AllPrintobjDebugAllPrint.csproj.GenerateResource.Cache

     文件      24064  2019-02-22 12:25  C#打印实例-全部打印源码实例AllPrintobjDebugAllPrint.exe

     文件      10728  2019-02-22 12:25  C#打印实例-全部打印源码实例AllPrintobjDebugAllPrint.Form1.resources

     文件      34304  2019-02-22 12:25  C#打印实例-全部打印源码实例AllPrintobjDebugAllPrint.pdb

     文件        180  2019-02-22 12:16  C#打印实例-全部打印源码实例AllPrintobjDebugAllPrint.Properties.Resources.resources

     文件        789  2019-02-22 12:16  C#打印实例-全部打印源码实例AllPrintobjDebugDesignTimeResolveAssemblyReferences.cache

     文件       6158  2019-02-22 12:25  C#打印实例-全部打印源码实例AllPrintobjDebugDesignTimeResolveAssemblyReferencesInput.cache

     文件       4608  2019-02-22 12:16  C#打印实例-全部打印源码实例AllPrintobjDebugTempPEProperties.Resources.Designer.cs.dll

     文件        489  2009-01-16 15:55  C#打印实例-全部打印源码实例AllPrintProgram.cs

     文件       1372  2009-01-16 15:55  C#打印实例-全部打印源码实例AllPrintPropertiesAssemblyInfo.cs

     文件       2856  2019-02-22 12:16  C#打印实例-全部打印源码实例AllPrintPropertiesResources.Designer.cs

     文件       5612  2009-01-16 15:55  C#打印实例-全部打印源码实例AllPrintPropertiesResources.resx

     文件       1108  2019-02-22 12:16  C#打印实例-全部打印源码实例AllPrintPropertiesSettings.Designer.cs

     文件        249  2009-01-16 15:55  C#打印实例-全部打印源码实例AllPrintPropertiesSettings.settings

     文件        914  2019-02-22 12:16  C#打印实例-全部打印源码实例AllPrint.sln

    ..A..H.     19456  2019-02-22 12:25  C#打印实例-全部打印源码实例AllPrint.suo

     文件       3762  2009-01-16 15:56  C#打印实例-全部打印源码实例BackupAllPrintAllPrint.csproj

     文件       5501  2009-01-16 15:59  C#打印实例-全部打印源码实例BackupAllPrintForm1.cs

     文件       5659  2009-01-16 15:58  C#打印实例-全部打印源码实例BackupAllPrintForm1.designer.cs

     文件      21736  2009-01-16 15:58  C#打印实例-全部打印源码实例BackupAllPrintForm1.resx

     文件        489  2009-01-16 15:55  C#打印实例-全部打印源码实例BackupAllPrintProgram.cs

............此处省略32个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)