C#中打印预览打印机设置和打印属性的方法+

上传人:鲁** 文档编号:509826723 上传时间:2023-07-04 格式:DOCX 页数:6 大小:38.05KB
返回 下载 相关 举报
C#中打印预览打印机设置和打印属性的方法+_第1页
第1页 / 共6页
C#中打印预览打印机设置和打印属性的方法+_第2页
第2页 / 共6页
C#中打印预览打印机设置和打印属性的方法+_第3页
第3页 / 共6页
C#中打印预览打印机设置和打印属性的方法+_第4页
第4页 / 共6页
C#中打印预览打印机设置和打印属性的方法+_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《C#中打印预览打印机设置和打印属性的方法+》由会员分享,可在线阅读,更多相关《C#中打印预览打印机设置和打印属性的方法+(6页珍藏版)》请在金锄头文库上搜索。

1、C#中打印预览打印机设置和打印属性的方法+C#中打印、预览、打印机设置和打印属性的方法 很久没有这样工作了,整天就为了一个问题而思考,但是还有分行部分没有弄清楚。 可能今天真的不能睡觉了。 能够整日的工作真是一种说不出的幸福。但愿这种感觉能够持续下去。 他娘的!我都语无伦次了! 这是今天的战绩: private void Form1_Load(object sender, System.EventArgs e) /获取或设置一个值,该值指示是否发送到文件或端口 printDocument1.PrinterSettings.PrintToFile = true; /设置打印时横向还是纵向 pri

2、ntDocument1.DefaultPageSettings.Landscape = true; private void fileOpenMenuItem_Click(object sender, System.EventArgs e) OpenFile; private void OpenFile openFileDialog1.Filter = Text Files (*.txt)|*.txt;/打开文本的类型 /获取文件对话框的初始目录获得bin文件下的文件 openFileDialog1.InitialDirectory = System.Windows.Forms.Applica

3、tion.StartupPath; DialogResult userResponse = openFileDialog1.ShowDialog; /MessageBox.Show(userResponse.ToString); if (userResponse=DialogResult.OK) filePath = openFileDialog1.FileName.ToString;/转换文件路径 private void MyPrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) /充分利用e int t

4、opMargin = printDocument1.DefaultPageSettings.Margins.Top;/上边距 int leftMargin = printDocument1.DefaultPageSettings.Margins.Left;/左边距 float linesPerPage = 0;/页面行号 float verticalPosition = 0;/绘制字符串的纵向位置 float horizontalPosition=leftMargin;/左边距 string textLine = null;/行字符串 currentLine = 0;/行计数器 / float

5、 Xline=0; /int line=0; / Calculate the number of lines per page. linesPerPage = e.MarginBounds.Height / myFont.GetHeight(e.Graphics); / Xline=e.MarginBounds.Width/myFont.GetHeight; / for each text line that will fit on the page, read a new line from the document while (currentLine linesPerPage ) tex

6、tLine = streamToPrint.ReadLine; if(textLine = null) break; / 求出已经打印的范围 verticalPosition = topMargin + currentLine * myFont.GetHeight(e.Graphics); / 设置页面的属性 e.Graphics.DrawString(textLine, myFont, myBrush, horizontalPosition, verticalPosition); / 增加行数 currentLine +; / If more lines of text exist in t

7、he file, print another page. if (textLine != null) e.HasMorePages = true; else e.HasMorePages = false; private void printPreviewButton_Click(object sender, System.EventArgs e) try streamToPrint = new StreamReader(filePath); try PrintPreview; finally streamToPrint.Close; catch(Exception ex) MessageBo

8、x.Show(ex.Message); private void runtimeDialogButton_Click(object sender, System.EventArgs e) try streamToPrint = new StreamReader(filePath); try RuntimeDialog; finally streamToPrint.Close; catch(Exception ex) MessageBox.Show(ex.Message); private void printPreviewControlButton_Click(object sender, S

9、ystem.EventArgs e) try streamToPrint = new StreamReader(filePath); try PrintPreviewControl; finally streamToPrint.Close; catch(Exception ex) MessageBox.Show(ex.Message); private void RuntimeDialog PrintPreviewDialog pPDlg; pPDlg = new PrintPreviewDialog; pPDlg.Document = pDoc; pPDlg.WindowState = Fo

10、rmWindowState.Maximized; pPDlg.PrintPreviewControl.Columns = 2; pPDlg.ShowDialog; pPDlg.Dispose; private void PrintPreviewControl Form formPreview = new Form; PrintPreviewControl previewControl = new PrintPreviewControl; previewControl.Document = printDocument1; previewControl.StartPage = 2; formPre

11、view.WindowState = FormWindowState.Maximized; formPreview.Controls.Add(previewControl); formPreview.Controls0.Dock = DockStyle.Fill; formPreview.ShowDialog; formPreview.Dispose; private void PrintPreview /设置页面的预览的页码 /设置显示页面显示的大小(也就是原页面的倍数) printPreviewDialog1.PrintPreviewControl.StartPage = 0; print

12、PreviewDialog1.PrintPreviewControl.Zoom =1.0; /设置或返回窗口状态,即该窗口是最小化、正常大小还是其他状态。 printPreviewDialog1.WindowState = FormWindowState.Maximized; /设置和获取需要预览的文档 /将窗体显示为指定者的模式对话框 printPreviewDialog1.Document = printDocument1; printPreviewDialog1.ShowDialog; private void PrintDoc printDialog1.Document = print

13、Document1; DialogResult userResPonse= printDialog1.ShowDialog; if(userResPonse=DialogResult.OK) printDocument1.Print; /获取打印机的设置和打印的属性 private void button1_Click(object sender, System.EventArgs e) try streamToPrint=new StreamReader(filePath); try PrintDoc; catch catch(Exception ex) MessageBox.Show(ex.Message); finally streamToPrint.Close;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号