• 大小: 8.12MB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2023-10-05
  • 语言: C#
  • 标签: C#  报表打印  源代码  

资源简介

C#报表打印的源代码,多种打印样式,共包含29个文件。

资源截图

代码片段和文件信息

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;

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

        #region 定义全局对象及变量
        int intPage = 0;//总页数
        int intRows = 0;//每页行数
        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 = 0;//行高 
        int leftmargin = 50;//左边距 
        int rightmargin = 50;//左边距
        int buttommargin = 80;//底边距 
        int columnWidth1 = 57;//第一列宽度
        int columnWidth2 = 335;//第二列宽度
        #endregion

        //初始化数据
        private void Form1_Load(object sender EventArgs e)
        {
            intRows = 20;
            SqlConnection sqlcon = new SqlConnection(“Data Source=(local);Database=Northwind;Uid=sa;Pwd=;“);
            SqlDataAdapter sqlda = new SqlDataAdapter(“select CustomerIDCompanyNameAddress from Customers“ sqlcon);
            DataSet myds = new DataSet();
            sqlda.Fill(myds);
            dataGridView1.DataSource = myds.Tables[0];
            //设置每列的宽度
            dataGridView1.Columns[0].Width = 57;
            dataGridView1.Columns[1].Width = 260;
            dataGridView1.Columns[2].Width = 280;
            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);
        }

        //打印
        private void button1_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.Dr

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

     文件       3726  2009-01-16 16:09  04-报表打印\20Print\20Print\20Print.csproj

     文件      23040  2009-01-16 16:09  04-报表打印\20Print\20Print\bin\Debug\20Print.exe

     文件      22016  2009-01-16 16:09  04-报表打印\20Print\20Print\bin\Debug\20Print.pdb

     文件      14328  2009-01-16 16:10  04-报表打印\20Print\20Print\bin\Debug\20Print.vshost.exe

     文件       5691  2009-01-16 16:09  04-报表打印\20Print\20Print\Form1.cs

     文件       4432  2009-01-16 16:09  04-报表打印\20Print\20Print\Form1.designer.cs

     文件      21736  2010-08-18 17:50  04-报表打印\20Print\20Print\Form1.resx

     文件        702  2009-01-16 16:10  04-报表打印\20Print\20Print\obj\Debug\20Print.csproj.FileListAbsolute.txt

     文件        847  2009-01-16 16:09  04-报表打印\20Print\20Print\obj\Debug\20Print.csproj.GenerateResource.Cache

     文件      23040  2009-01-16 16:09  04-报表打印\20Print\20Print\obj\Debug\20Print.exe

     文件      22016  2009-01-16 16:09  04-报表打印\20Print\20Print\obj\Debug\20Print.pdb

     文件      10728  2009-01-16 16:09  04-报表打印\20Print\20Print\obj\Debug\_20Print.Form1.resources

     文件        180  2009-01-16 16:09  04-报表打印\20Print\20Print\obj\Debug\_20Print.Properties.Resources.resources

     文件        489  2009-01-16 16:06  04-报表打印\20Print\20Print\Program.cs

     文件       1370  2009-01-16 16:06  04-报表打印\20Print\20Print\Properties\AssemblyInfo.cs

     文件       2866  2009-01-16 16:06  04-报表打印\20Print\20Print\Properties\Resources.Designer.cs

     文件       5612  2009-01-16 16:06  04-报表打印\20Print\20Print\Properties\Resources.resx

     文件       1093  2009-01-16 16:06  04-报表打印\20Print\20Print\Properties\Settings.Designer.cs

     文件        249  2009-01-16 16:06  04-报表打印\20Print\20Print\Properties\Settings.settings

     文件        911  2009-01-16 16:06  04-报表打印\20Print\20Print.sln

    ..A..H.     13312  2009-01-16 16:10  04-报表打印\20Print\20Print.suo

     文件       3761  2009-01-16 16:14  04-报表打印\30Print\30Print\30Print.csproj

     文件      23040  2009-01-16 16:14  04-报表打印\30Print\30Print\bin\Debug\30Print.exe

     文件      22016  2009-01-16 16:14  04-报表打印\30Print\30Print\bin\Debug\30Print.pdb

     文件      14328  2009-01-16 16:15  04-报表打印\30Print\30Print\bin\Debug\30Print.vshost.exe

     文件       5691  2009-01-16 16:14  04-报表打印\30Print\30Print\Form1.cs

     文件       4432  2009-01-16 16:14  04-报表打印\30Print\30Print\Form1.designer.cs

     文件      21736  2009-01-16 16:12  04-报表打印\30Print\30Print\Form1.resx

     文件        702  2009-01-16 16:15  04-报表打印\30Print\30Print\obj\Debug\30Print.csproj.FileListAbsolute.txt

     文件        847  2009-01-16 16:14  04-报表打印\30Print\30Print\obj\Debug\30Print.csproj.GenerateResource.Cache

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

评论

共有 条评论