資源簡介
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#打印實例-全部打印源碼實例\AllPrint\AllPrint.csproj
?????文件??????24064??2019-02-22?12:25??C#打印實例-全部打印源碼實例\AllPrint\bin\Debug\AllPrint.exe
?????文件??????34304??2019-02-22?12:25??C#打印實例-全部打印源碼實例\AllPrint\bin\Debug\AllPrint.pdb
?????文件??????11608??2019-02-22?12:25??C#打印實例-全部打印源碼實例\AllPrint\bin\Debug\AllPrint.vshost.exe
?????文件????????490??2013-03-18?17:00??C#打印實例-全部打印源碼實例\AllPrint\bin\Debug\AllPrint.vshost.exe.manifest
?????文件???????5476??2019-02-22?12:25??C#打印實例-全部打印源碼實例\AllPrint\Form1.cs
?????文件???????6523??2019-02-22?12:25??C#打印實例-全部打印源碼實例\AllPrint\Form1.designer.cs
?????文件??????21736??2019-02-22?12:25??C#打印實例-全部打印源碼實例\AllPrint\Form1.resx
?????文件???????1840??2019-02-22?12:25??C#打印實例-全部打印源碼實例\AllPrint\obj\Debug\AllPrint.csproj.FileListAbsolute.txt
?????文件????????847??2019-02-22?12:25??C#打印實例-全部打印源碼實例\AllPrint\obj\Debug\AllPrint.csproj.GenerateResource.Cache
?????文件??????24064??2019-02-22?12:25??C#打印實例-全部打印源碼實例\AllPrint\obj\Debug\AllPrint.exe
?????文件??????10728??2019-02-22?12:25??C#打印實例-全部打印源碼實例\AllPrint\obj\Debug\AllPrint.Form1.resources
?????文件??????34304??2019-02-22?12:25??C#打印實例-全部打印源碼實例\AllPrint\obj\Debug\AllPrint.pdb
?????文件????????180??2019-02-22?12:16??C#打印實例-全部打印源碼實例\AllPrint\obj\Debug\AllPrint.Properties.Resources.resources
?????文件????????789??2019-02-22?12:16??C#打印實例-全部打印源碼實例\AllPrint\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6158??2019-02-22?12:25??C#打印實例-全部打印源碼實例\AllPrint\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????4608??2019-02-22?12:16??C#打印實例-全部打印源碼實例\AllPrint\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll
?????文件????????489??2009-01-16?15:55??C#打印實例-全部打印源碼實例\AllPrint\Program.cs
?????文件???????1372??2009-01-16?15:55??C#打印實例-全部打印源碼實例\AllPrint\Properties\AssemblyInfo.cs
?????文件???????2856??2019-02-22?12:16??C#打印實例-全部打印源碼實例\AllPrint\Properties\Resources.Designer.cs
?????文件???????5612??2009-01-16?15:55??C#打印實例-全部打印源碼實例\AllPrint\Properties\Resources.resx
?????文件???????1108??2019-02-22?12:16??C#打印實例-全部打印源碼實例\AllPrint\Properties\Settings.Designer.cs
?????文件????????249??2009-01-16?15:55??C#打印實例-全部打印源碼實例\AllPrint\Properties\Settings.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#打印實例-全部打印源碼實例\Backup\AllPrint\AllPrint.csproj
?????文件???????5501??2009-01-16?15:59??C#打印實例-全部打印源碼實例\Backup\AllPrint\Form1.cs
?????文件???????5659??2009-01-16?15:58??C#打印實例-全部打印源碼實例\Backup\AllPrint\Form1.designer.cs
?????文件??????21736??2009-01-16?15:58??C#打印實例-全部打印源碼實例\Backup\AllPrint\Form1.resx
?????文件????????489??2009-01-16?15:55??C#打印實例-全部打印源碼實例\Backup\AllPrint\Program.cs
............此處省略32個文件信息
評論
共有 條評論