资源大小: 37KB
发布时间: 2009-01-09
文件格式: rar
下载次数: 0
分享到:

下载地址:

下载地址1
(本站为飞网专业下载站,域名:down.cfei.net)

资源简介:

打印方法小议,页面设置对话框、打印预览对话框、打印对话框等功能,C#源代码 //字符串流对象,一行一行读取文本 private StringReader MyReader; private void button1_Click(object sender, EventArgs e) { //显示页面设置对话框 PageSetupDialog MyDlg = new PageSetupDialog(); MyDlg.Document = this.printDocument1; MyDlg.ShowDialog(); } private void button2_Click(object sender, EventArgs e) { //显示打印预览对话框 PrintPreviewDialog MyDlg = new PrintPreviewDialog(); MyDlg.Document = this.printDocument1; this.MyReader = new StringReader(this.richTextBox1.Text); MyDlg.ShowDialog(); } private void button3_Click(object sender, EventArgs e) { //显示打印对话框 PrintDialog MyDlg = new PrintDialog(); MyDlg.Document = this.printDocument1; MyDlg.ShowDialog(); } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { Graphics g = e.Graphics; //每一页的行数 float MyLines = e.MarginBounds.Height / this.richTextBox1.Font.GetHeight(g); //打印时的行计数器 int MyLineNumber = 0; //打印时的纵坐标 float MyYPosition = 0; float MyMarginLeft = e.MarginBounds.Left; float MyMarginTop = e.MarginBounds.Top; //每一行要打印的文本 string MyLine = ""; while ((MyLineNumber < MyLines) && ((MyLine = MyReader.ReadLine()) != null)) { MyYPosition = MyMarginTop + MyLineNumber * this.richTextBox1.Font.GetHeight(g); g.DrawString(MyLine, this.richTextBox1.Font, new SolidBrush(Color.Black), MyMarginLeft, MyYPosition, new StringFormat()); MyLineNumber++; } if (MyLine != null) { //发出下一次PrintPage事件 e.HasMorePages = true; } else { e.HasMorePages = false; }


飞网下载站,免费下载共享资料,内容涉及教育资源、专业资料、IT资源、娱乐生活、经济管理、办公文书、游戏资料等。