資源簡介
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個文件信息
評論
共有 條評論