日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

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

發布時間:2023/12/9 C# 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C# 中打印、预览、打印机设置和打印属性的方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
private void Form1_Load(object sender, System.EventArgs e)
??{
???//獲取或設置一個值,該值指示是否發送到文件或端口
???printDocument1.PrinterSettings.PrintToFile = true;
???//設置打印時橫向還是縱向
???printDocument1.DefaultPageSettings.Landscape = true;
??}
??private void fileOpenMenuItem_Click(object sender, System.EventArgs e)
??{
???OpenFile();
??}
??private void OpenFile()
??{
???openFileDialog1.Filter = "Text Files (*.txt)|*.txt";//打開文本的類型
???//獲取文件對話框的初始目錄(StartupPath)獲得bin文件下的文件
???openFileDialog1.InitialDirectory = System.Windows.Forms.Application.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 topMargin = 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 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 )
???{
????textLine = 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 the 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();
????}
??

轉載于:https://www.cnblogs.com/zengjiliang/archive/2011/10/08/2202091.html

總結

以上是生活随笔為你收集整理的C# 中打印、预览、打印机设置和打印属性的方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。