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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

silverlight 调用默认打印机

發布時間:2025/3/20 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 silverlight 调用默认打印机 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

打印輔助類。

首先添加

using System.Windows.Printing;

命名空間

1 public class SilverPrint 2 { 3 //設置每一項之間的間距 4 int listPrintIndex = 0; 5 private List<PrintStr> listStr = null; 6 public void Print(List<PrintStr> strs) 7 { 8 listStr = strs; 9 PrintDocument printDoc = new PrintDocument(); 10 printDoc.PrintPage += OnPrintPage; 11 PrinterFallbackSettings settings = new PrinterFallbackSettings(); 12 settings.ForceVector = true; 13 printDoc.Print("dd", settings, true);//dd是文檔的名字 14 } 15 public void OnPrintPage(object sender, PrintPageEventArgs e) 16 { 17 Canvas printSurface = new Canvas(); 18 //得到最頂端位置 19 double topPosition = e.PageMargins.Top; 20 //遍歷當前的ListBox.Items 21 while (listPrintIndex < listStr.Count) 22 { 23 //實例化TextBlock用來存放每一行的值 24 TextBlock txt = new TextBlock(); 25 txt.FontSize = listStr[listPrintIndex].FontSize; 26 txt.Text = listStr[listPrintIndex].Content; 27 double measuredHeight = txt.ActualHeight; 28 //如果打印的當前行高度不合適的話,則進行分頁 29 if (measuredHeight > (e.PrintableArea.Height - topPosition)) 30 { 31 e.HasMorePages = true; 32 topPosition = e.PageMargins.Top; 33 break; 34 } 35 //設置TextBlock在Canvas中的位置 36 txt.SetValue(Canvas.TopProperty, topPosition); 37 txt.SetValue(Canvas.LeftProperty, e.PageMargins.Left); 38 //將TextBlock添加到打印的元素中去 39 printSurface.Children.Add(txt); 40 listPrintIndex++; 41 //追加高度 42 topPosition = topPosition + measuredHeight; 43 } 44 e.PageVisual = printSurface; 45 } 46 } 47 //打印內容類 48 public class PrintStr 49 { 50 public string Content { set; get; } 51 public int FontSize { set; get; } 52 public PrintStr(string str,int size=10) 53 { 54 this.Content = str; 55 this.FontSize = size; 56 } 57 }

打印直接調用

new SilverPrint().Print(printStrs);

如果是silverlight5.0之前會彈出打印預覽。。。如果是silverlight5.0 允許瀏覽器外允許 增加權限。就可以不用彈出打印預覽,直接打印了

總結

以上是生活随笔為你收集整理的silverlight 调用默认打印机的全部內容,希望文章能夠幫你解決所遇到的問題。

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