版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、項目六:打印輸出項目六:打印輸出主講人:艾長春教學目的要求:教學目的要求:1、掌握、掌握PrintDocument類的對象的常用屬性和類的對象的常用屬性和方法、事件;方法、事件;2、掌握、掌握PrintPreviewDialog類的對象的常用屬類的對象的常用屬性和方法;性和方法;3、學會用、學會用Font類的對象定義。類的對象定義。4、掌握字符串對象、表格、圖片的打印輸出、掌握字符串對象、表格、圖片的打印輸出方法,學習分頁打印。方法,學習分頁打印。教學重點、難點:教學重點、難點:字符串的輸出、圖片的輸出字符串的輸出、圖片的輸出學而不思則罔,思而不學則殆學而不思則罔,思而不學則殆命名空間:usi
2、ng System.IO ;using System.Drawing.Printing;在類中創(chuàng)建對象:文檔對象、預覽對象、畫筆對象、字體對象private System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();/創(chuàng)建打印文檔private PrintPreviewDialog prv = new PrintPreviewDialog();/創(chuàng)建打印預覽對話框private string prText =null ;/打印內(nèi)容Brush br = Brushes.Red;/創(chuàng)
3、建紅色畫筆Font f= new Font(“Arial”, 30);/設置字體PointF pf = new PointF(140,140);/定義打印的起始位置建立打印事件:private void pd_PrintPage(object sender,PrintPageEventArgs ev)/建立打印控制事件 if (f = null & br = null)/如果沒有設置打印字體和畫筆就用10號字,黑色 ev.Graphics.DrawString(prText, new Font (Arial,10),Brushes .Black ,new PointF(ev.Margi
4、nBounds .Left ,ev.MarginBounds .Top ); else ev.Graphics.DrawString(prText, f, br, pf); 用打印機進行打印一行文字。用打印機進行打印一行文字。打印按鈕代碼: prText = tbx_prText.Text; PointF pf = new PointF(this .Width /2-20,this .Height /2-20);/定義打印的起始位置 if (prText.Length = 0) MessageBox.Show(沒有打印內(nèi)容!); return; pd.PrintPage +=new Print
5、PageEventHandler(pd_PrintPage); pd.Print();/開始打印 打印預覽按鈕代碼 prText = tbx_prText.Text; PointF pf = new PointF(this.Width / 2 - 20, this.Height / 2 - 20);/定義打印的起始位置 if (prText.Length = 0) MessageBox.Show(沒有打印內(nèi)容!); return; pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); prv.Document = pd; prv.Sh
6、owDialog();PrintDocument類1、 PrintDocument對象常用的屬性:對象常用的屬性:DefultPageSettings屬性:讀寫屬性。這是頁的設置用于要打?qū)傩裕鹤x寫屬性。這是頁的設置用于要打印的所有頁的默認設置。印的所有頁的默認設置。DocumentName屬性:讀寫屬性。打印文檔時要顯示的文檔屬性:讀寫屬性。打印文檔時要顯示的文檔名(在打印狀態(tài)對話框或打印隊列中顯示)。名(在打印狀態(tài)對話框或打印隊列中顯示)。OriginAtMargins屬性:讀寫屬性。與面關(guān)聯(lián)的圖形對象的位屬性:讀寫屬性。與面關(guān)聯(lián)的圖形對象的位置是位于用戶指定的邊距內(nèi),還是位于該頁打印區(qū)域的
7、左上角。置是位于用戶指定的邊距內(nèi),還是位于該頁打印區(qū)域的左上角。PrintController屬性:獲取或設置打印進程的打印控制器。屬性:獲取或設置打印進程的打印控制器。PrintSettings屬性:獲取或設置對文檔進行打印的打印機。屬性:獲取或設置對文檔進行打印的打印機。2、PrintDocument的方法的方法Print():如果不需要預覽或設置打印機,可以直接調(diào)用如果不需要預覽或設置打印機,可以直接調(diào)用Print方方法進行打印。如:法進行打印。如:pd.Print();3、PrintDocument的事件的事件PrintPage:當需要打印當前頁并輸出時發(fā)生。只有設置了打:當需要打印當
8、前頁并輸出時發(fā)生。只有設置了打印內(nèi)容后,才能打印輸出。印內(nèi)容后,才能打印輸出。創(chuàng)建打印文檔的方法:創(chuàng)建打印文檔的方法:System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();聲明打印文檔的打印當前頁事件:聲明打印文檔的打印當前頁事件:pd.PrintPage +=new PrintPageEventHandler(pd_PrintPage);創(chuàng)建打印文檔的打印頁事件過程:創(chuàng)建打印文檔的打印頁事件過程:private void pd_PrintPage(object sender
9、,PrintPageEventArgs ev) 設置打印的內(nèi)容;打印文檔調(diào)用打印方法:打印文檔調(diào)用打印方法:pd.Print();打印字符串的方法:打印字符串的方法:ev.Graphics.DrawString(字符串, 字體, 畫刷, 打印起始點);字體設置格式:字體設置格式:Font f= new Font(“字體”, 字號,字型,單位);畫刷的定義:畫刷的定義:Brush br = Brushes.Red;PrintPreviewDialog類1、PrintPreviewDialog的屬性Document:獲取或設置預覽的文檔。如:prv.Documet=pd;Modal:是否有模式地顯
10、示上窗口。2、打印位置如:ev.Graphics.DrawString(line, printFont, Brushes.Black, new PointF(ev.MarginBounds.Left, ev.MarginBounds.Top);用于調(diào)整位置的值: new PointF(ev.MarginBounds.Left, ev.MarginBounds.Top)設計用打印機打印表格。設計用打印機打印表格。命名空間:using System.Data.SqlClient;using System.Drawing .Printing ;using System.IO;定義類的成員變量:Sql
11、Connection con = new SqlConnection(server=.;database=stuM;integrated security=true);DataTable dt = new DataTable();private Font printFont = null;/設置打印字體string couresName = “”;/打印的課程名int n = 0;/確定行數(shù)string className;/打印的班級名數(shù)組string RenShu;/打印的人 數(shù)數(shù)組string Sumf;/打印的班級總分string RenshuTotal;/匯總?cè)撕嫌媠tring Su
12、mTotal;/匯總總分合計窗體裝入事件代碼string sqlstr = select * from couresTab;SqlDataAdapter da = new SqlDataAdapter(sqlstr, con);DataTable dt = new DataTable();da.Fill(dt);cbx_KC.DataSource = dt;cbx_KC.DisplayMember = couresName;cbx_KC.ValueMember = couresId;cbx_KC.SelectedIndex = 0;組合框選擇改變事件代碼SqlCommand com = new
13、 SqlCommand(KCTJ,con);com.CommandType = CommandType.StoredProcedure;com.Parameters.Add(kcId, SqlDbType.NVarChar, 2).Value = cbx_KC.SelectedValue.ToString ();com.Parameters.Add(bjzs, SqlDbType.Int);com.Parameters1.Direction = ParameterDirection.Output;SqlDataAdapter da = new SqlDataAdapter(com);dt.Cl
14、ear();da.Fill(dt);dataGridView1 .DataSource =dt;label3 .Text =班級總數(shù):+com .Parametersbjzs.Value .ToString ();couresName = cbx_KC.Text; 打印按鈕單擊事件代碼: n = dt.Rows.Count; className=new stringn;/班級名稱 RenShu = new stringn;/考試人數(shù) Sumf = new stringn;/總分 int RSTotal = 0;/人數(shù)合計 double SumfTotal = 0;/總分合計 for (int
15、i=0;in;i+) classNamei = dt.Rowsi0.ToString(); RenShui = dt.Rowsi1.ToString(); RSTotal = RSTotal + int.Parse (dt.Rowsi1.ToString (); Sumfi = dt.Rowsi2.ToString(); SumfTotal = SumfTotal + double.Parse(dt.Rowsi2.ToString(); RenshuTotal = RSTotal.ToString(); SumTotal = SumfTotal.ToString(); printFont =
16、new Font(Arial, 10); PrintDocument pd = new PrintDocument();/建立打印的文檔 PaperSize ps = new PaperSize();/定義紙張的大小 ps.RawKind = 9;/8是A3紙,9是A4紙,10是A4小,11是A5,12是B4,13是B5,大于118是自定義紙張、可以定義紙張的寬度和高度。 /ps.Height = 370;/定義紙的高度 /ps.Width = 854;/定義紙的寬度 pd.DefaultPageSettings.PaperSize = ps; pd.DefaultPageSettings.L
17、andscape = true;/控件打印紙的方向,True是橫向打印,默認為false縱向打印。 pd.PrintPage +=new PrintPageEventHandler(pd_PrintPage);/調(diào)用打印事件 PageSetupDialog psd = new PageSetupDialog();/頁面設置對話框 psd.ShowNetwork = false;/頁面設置對話框的打印按鈕對話框中的遠程網(wǎng)絡按鈕是否可見 psd.PageSettings = new PageSettings();/用于單頁打印的頁設置 psd.ShowDialog(); pd.PrinterSet
18、tings = psd.PrinterSettings;/獲取或設置與該頁關(guān)聯(lián)的打印機的設置 pd.DefaultPageSettings = psd.PageSettings; pd.Print(); 用制表符來畫表格 private void pd_PrintPage(object sender, PrintPageEventArgs ev)/定義打印事件 /以下代碼是用制表符打印表格,質(zhì)量差,主要是制表符對不齊 Single linesPerPage = 0;/每一頁的行數(shù) Single yPos = 0; int count = 0; Single leftMargin =ev.Mar
19、ginBounds .Left + 20;/左頁邊距 Single topMargin = ev .MarginBounds .Top -30;/上頁邊距 string line = null; linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);/每一頁的打印行數(shù),為頁的高度除以打印字體的高度 /打印第一行 line = 班級成績統(tǒng)計; printFont = new Font(Arial, 30); yPos = topMargin + count * printFont.GetHeight(ev
20、.Graphics); ev.Graphics.DrawString(line, printFont, Brushes.Blue , leftMargin+40, yPos, new StringFormat(); /打印第二行,打印課程名,打印日期 line = 課程名: + couresName + + System.DateTime.Now.ToString(); printFont = new Font(Arial, 10); count = count + 1; yPos = topMargin + count * printFont.GetHeight(ev.Graphics)+4
21、0; ev.Graphics.DrawString(line, printFont, Brushes.Red, leftMargin, yPos, new StringFormat(); /打印第三行,主要是制表符 line = ; count = count + 1; yPos = topMargin + count * printFont.GetHeight(ev.Graphics)+40; ev.Graphics.DrawString(line, printFont, Brushes.Green , leftMargin, yPos, new StringFormat(); line =
22、 ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 106, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 212, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green , leftMargin+318, yPos, new
23、 StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 424, yPos, new StringFormat(); /打印第四行 count = count + 1; line = ; yPos = topMargin + count * printFont.GetHeight(ev.Graphics)+40; ev.Graphics.DrawString(line, printFont, Brushes.Green , leftMargin, yPos, ne
24、w StringFormat(); line = 班級名稱:; ev.Graphics.DrawString(line, printFont, Brushes.Green , leftMargin+20, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green , leftMargin+110, yPos, new StringFormat(); line = 人數(shù); ev.Graphics.DrawString(line, printFont, Brushes.Green
25、 , leftMargin + 130, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green , leftMargin + 216, yPos, new StringFormat(); line = 總分; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 238, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(li
26、ne, printFont, Brushes.Green, leftMargin + 322, yPos, new StringFormat(); line = 備注; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 346, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 424, yPos, new StringFormat(); /打印第五行 c
27、ount = count + 1; line = ; yPos = topMargin + count * printFont.GetHeight(ev.Graphics) + 40; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 106, yPos, new StringFormat(); line =
28、 ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 212, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 318, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 424, yPos, ne
29、w StringFormat(); /第六行后,可能有多行 printFont = new Font(Arial, 10); for (int i = 0; i n; i+) count = count + 1; line = ; yPos = topMargin + count * printFont.GetHeight(ev.Graphics) + 40; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin, yPos, new StringFormat(); line = className i; ev.Gr
30、aphics.DrawString(line, printFont, Brushes.Green, leftMargin + 20, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 110, yPos, new StringFormat(); line = RenShu i; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 130, yPos, new
31、 StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 216, yPos, new StringFormat(); line = Sumfi; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 238, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green
32、, leftMargin + 322, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 424, yPos, new StringFormat(); count = count + 1; line = ; yPos = topMargin + count * printFont.GetHeight(ev.Graphics) + 40; ev.Graphics.DrawString(line, printFont, Brushes.Gree
33、n, leftMargin, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 106, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 212, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, print
34、Font, Brushes.Green, leftMargin + 318, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 424, yPos, new StringFormat(); /表格的匯總行 count = count + 1; line = ; yPos = topMargin + count * printFont.GetHeight(ev.Graphics) + 40; ev.Graphics.DrawString(li
35、ne, printFont, Brushes.Green, leftMargin, yPos, new StringFormat(); line = 匯總; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 20, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 110, yPos, new StringFormat(); line = RenshuTo
36、tal.ToString(); ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 130, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 216, yPos, new StringFormat(); line = SumTotal.ToString(); ev.Graphics.DrawString(line, printFont, Brushes.G
37、reen, leftMargin + 238, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 322, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 424, yPos, new StringFormat(); count = count + 1; line = ; yPos =
38、 topMargin + count * printFont.GetHeight(ev.Graphics) + 40; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 106, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, p
39、rintFont, Brushes.Green, leftMargin + 212, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 318, yPos, new StringFormat(); line = ; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin + 424, yPos, new StringFormat(); line = null; /如
40、果有更多的行,打印另一些頁 if (line != null) ev.HasMorePages = true; else ev.HasMorePages = false; 打印預覽按鈕代碼: n = dt.Rows.Count; className = new stringn;/班級名稱 RenShu = new stringn;/考試人數(shù) Sumf = new stringn;/總分 int RSTotal = 0;/人數(shù)合計 double SumfTotal = 0;/總分合計 for (int i = 0; i n; i+) classNamei = dt.Rowsi0.ToString
41、(); RenShui = dt.Rowsi1.ToString(); RSTotal = RSTotal + int.Parse(dt.Rowsi1.ToString(); Sumfi = dt.Rowsi2.ToString(); SumfTotal = SumfTotal + double.Parse(dt.Rowsi2.ToString(); RenshuTotal = RSTotal.ToString(); SumTotal = SumfTotal.ToString(); printFont = new Font(Arial, 10); PrintDocument pd = new
42、PrintDocument();/建立打印的文檔 pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);/調(diào)用打印事件 PageSetupDialog psd = new PageSetupDialog();/頁面設置對話框 psd.ShowNetwork = false;/頁面設置對話框的打印按鈕對話框中的遠程網(wǎng)絡按鈕是否可見 psd.PageSettings = new PageSettings();/用于單頁打印的頁設置 psd.ShowDialog(); pd.PrinterSettings = psd.PrinterSetti
43、ngs;/獲取或設置與該頁關(guān)聯(lián)的打印機的設置 pd.DefaultPageSettings = psd.PageSettings; PrintPreviewDialog prv = new PrintPreviewDialog();/預覽對話框 prv.Document = pd; prv.ShowDialog(); 打印預覽對象的創(chuàng)建:打印預覽對象的創(chuàng)建:PrintPreviewDialog prv = new PrintPreviewDialog();預覽的內(nèi)容的建立:預覽的內(nèi)容的建立:prv.Document = pd;進行預覽:進行預覽:prv.ShowDialog();打印頁面設置對
44、話框的建立:打印頁面設置對話框的建立:PageSetupDialog ps = new PageSetupDialog();打印線條圖形的方法:打印線條圖形的方法:ev.Graphics.DrawLine(畫筆, 起始位置, 終止位置);畫筆的定義:畫筆的定義:Pen p = new Pen(畫筆的顏色, 畫筆的寬度); 打印機打印事件的代碼改為以下代碼: Single linesPerPage = 0, startX = 0, startY = 0, Y;/startX = 0, startY = 0,Y文字輸出的打印點坐標 int count = 0, startPX = 0, start
45、PY = 0, endPX = 0, endPY = 0;/count記錄行數(shù),其他的記錄表格線條坐標位置 startX = ev.MarginBounds.Left + 120;/ev.MarginBounds .Left左頁邊距 startY = ev .MarginBounds .Top+30;/上頁邊距 string line = null; linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);/每一頁的打印行數(shù),為頁的高度除以打印字體的高度 /打印第一行 ; line =Space (6)+
46、 班級成績統(tǒng)計; printFont = new Font(Arial, 30);/第一行字的字體、字號 Y = startY + count * printFont.GetHeight(ev.Graphics); ; ev.Graphics.DrawString(line, printFont, Brushes.Blue, startX, Y, new StringFormat(); /打印第二行,打印課程名,打印日期 line = 課程名: + couresName + Space(50) + System.DateTime.Now.ToString(); count = count +
47、1; printFont = new Font(Arial, 10);/后面要打印字的字體,字號 Y = startY + count * printFont.GetHeight(ev.Graphics)+40; ev.Graphics.DrawString(line, printFont, Brushes.Red, startX, Y, new StringFormat(); /計算畫第一條表格線的起始坐標和終止坐標位置 startPX = (int)startX; startPY = (int)Y + (count + 1) * 16 - 8;/10號字的高度是16,減8是為了畫的線在這一
48、行的中間 endPX = startPX + 440; endPY = startPY; /第四行 count = count + 2; Y = startY + count * printFont.GetHeight(ev.Graphics)+40; line = 班級名稱; ev.Graphics.DrawString(line, printFont, Brushes.Green, startX + 20, Y, new StringFormat(); line = 人數(shù); ev.Graphics.DrawString(line, printFont, Brushes.Green, sta
49、rtX + 130, Y, new StringFormat(); line = 總分; ev.Graphics.DrawString(line, printFont, Brushes.Green, startX + 240, Y, new StringFormat(); line = 備注; ev.Graphics.DrawString(line, printFont, Brushes.Green, startX + 350, Y, new StringFormat(); /第六行后,可能有多行,n是查詢得到數(shù)據(jù)的行數(shù) for (int i = 0; i n; i+) count = cou
50、nt + 2; Y = startY + count * printFont.GetHeight(ev.Graphics) + 40; line = className i; ev.Graphics.DrawString(line, printFont, Brushes.Green, startX + 20, Y, new StringFormat(); line = RenShu i; ev.Graphics.DrawString(line, printFont, Brushes.Green, startX + 130, Y, new StringFormat(); line = Sumfi
51、; ev.Graphics.DrawString(line, printFont, Brushes.Green, startX + 240, Y, new StringFormat(); /表格的匯總行 count = count + 2; Y = startY + count * printFont.GetHeight(ev.Graphics) + 40; line = 匯總; ev.Graphics.DrawString(line, printFont, Brushes.Green, startX + 20, Y, new StringFormat(); line = RenshuTota
52、l.ToString(); ev.Graphics.DrawString(line, printFont, Brushes.Green, startX + 130,Y, new StringFormat(); line = SumTotal.ToString(); ev.Graphics.DrawString(line, printFont, Brushes.Green, startX + 240, Y, new StringFormat(); /計算畫最后一條表格線條的起始位置和終止位置 /畫橫線,畫線條數(shù)應該是數(shù)據(jù)行n+標題行1+匯總行1+1 for (int i = 0; i n + 3
53、; i+) Pen p = new Pen(Color.Red, 1);/定義畫筆及畫筆的顏色和寬度 Point startP = new Point(startPX, startPY); Point endP = new Point(endPX, endPY); ev.Graphics.DrawLine(p, startP, endP); startPY = startPY + 2 * 16;/下一條線的y坐標位置,10號字符的高度是16 endPY = startPY; /畫縱線 endPY = endPY - 32; endPX = startPX; startPX = endPX; s
54、tartPY = endPY - (n + 2) * 2 * 16; for (int j = 0; j 5; j+) Pen p = new Pen(Color.Red, 1);/定義畫筆及畫筆的顏色和寬度 Point startP = new Point(startPX, startPY); Point endP = new Point(endPX, endPY); ev.Graphics.DrawLine(p, startP, endP); startPX = startPX + 110;/每一個列寬是110 endPX = startPX; line = null; /如果有更多的行,
55、打印另一些頁 if (line != null) ev.HasMorePages = true; else ev.HasMorePages = false;優(yōu)點:表格打印優(yōu)點:表格打印線條無縫對接,線條無縫對接,沒有制表符哪樣沒有制表符哪樣的接口。的接口。在表格中輸出圖片并分頁打印。添加命名空間: using System.Drawing.Printing;添加類的成員變量: DataSet ds1 = new DataSet(); int n = 0;/存儲數(shù)據(jù)集的記錄數(shù) private System .Drawing . Font printFont = new System.Drawin
56、g.Font(Arial, 10);/設置打印字體 string stuNo ;/學號 string stuName ;/學生名稱 string Sex ;/性別 string Birthday ;/出生日期 string Tel;/電話 Bitmap img ;/圖片 int pageCount = 0;/用于控制當前打印的頁數(shù) int k = 0;/用于控制當前打印的記錄的記錄號 int m = 0;/用于控制每頁打印的最后一條記錄的記錄號打印事件代碼:private void pd_PrintPage(object sender, PrintPageEventArgs ev)/定義打印事
57、件 pageCount+; if (pageCount = System.Math.Ceiling(n / 7.0)/每頁打印7條記錄的信息,n是記錄的總條數(shù) ev.HasMorePages = true;/可以實現(xiàn)分頁打印 m = pageCount * 7 - 1;/每一頁最后一條記錄的記錄號的最大可能值 k = pageCount * 7 - 7;/每一條的第一條記錄的記錄號 /以下代碼是用制表符打印表格 Single yPos = 0; int count = 0; Single leftMargin = 120;/左頁邊距 Single topMargin = ev.MarginBo
58、unds.Top - 30;/上頁邊距 string line = null; /打印第一行 line = 學生花名冊名片; printFont = new System.Drawing.Font (Arial, 30); yPos = topMargin + count * printFont.GetHeight(ev.Graphics); ev.Graphics.DrawString(line, printFont, Brushes.Blue, leftMargin+50, yPos, new StringFormat(); /打印第二行,打印日期 line = 打印日期: + Syste
59、m.DateTime.Now.ToString(); printFont = new System.Drawing .Font (Arial, 10); count = count + 1; yPos = topMargin + count * printFont.GetHeight(ev.Graphics) + 40; ev.Graphics.DrawString(line, printFont, Brushes.Red, leftMargin+100, yPos, new StringFormat(); /打印第三行,主要是制表符 for (; k = n)/當前要打印的記錄的記錄號超過或
60、者等于數(shù)據(jù)集的記錄數(shù)時,不再打印多頁,并退出循環(huán) ev.HasMorePages = false; line = null; img = null; pageCount = 0; break; count = count + 1; line = ; yPos = topMargin + count * printFont.GetHeight(ev.Graphics) + 40; ev.Graphics.DrawString(line, printFont, Brushes.Green, leftMargin, yPos, new StringFormat(); line = ; ev.Graphics
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五版苗木種植與農(nóng)業(yè)綜合開發(fā)合同樣本4篇
- 二零二五年度教育培訓股東股權(quán)轉(zhuǎn)讓與合作辦學合同2篇
- 二零二五版嬰幼兒奶粉國際市場拓展與出口合同4篇
- 2025版綠色環(huán)保型商品房預售買賣合同3篇
- 2025年度校服品牌授權(quán)與校園形象塑造合同3篇
- 2025年度事業(yè)單位合同工勞動法執(zhí)行監(jiān)督評估合同3篇
- 2025年度生鮮配送冷鏈物流承包合同范本3篇
- 2025年度個人傭金提成與長期激勵合同2篇
- 課題申報參考:能源數(shù)據(jù)要素賦能可再生能源電力生產(chǎn)的機制與對策研究
- 課題申報參考:民族傳統(tǒng)體育與體育非物質(zhì)文化遺產(chǎn)的傳承與保護研究
- 2025年N1叉車司機考試試題(附答案)
- 《醫(yī)院財務分析報告》課件
- 2025老年公寓合同管理制度
- 2024-2025學年人教版數(shù)學六年級上冊 期末綜合卷(含答案)
- 2024中國汽車后市場年度發(fā)展報告
- 感染性腹瀉的護理查房
- 天津市部分區(qū)2023-2024學年高二上學期期末考試 物理 含解析
- 《人工智能基礎(chǔ)》全套英語教學課件(共7章)
- GB/T 35613-2024綠色產(chǎn)品評價紙和紙制品
- 2022-2023學年五年級數(shù)學春季開學摸底考(四)蘇教版
- 【螞蟻?!?024中國商業(yè)醫(yī)療險發(fā)展研究藍皮書
評論
0/150
提交評論