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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Silverlight4 多页打印实现

發布時間:2024/8/1 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Silverlight4 多页打印实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

silverlight4 中需要編碼來指示打印多頁,舉個例子來說明如何實現。?

XAML如下:

<ScrollViewer VerticalScrollBarVisibility="Auto" Margin="8" BorderThickness="0"><StackPanel Name="spQues"></StackPanel></ScrollViewer>?

StackPanel?"spQues"的子項通過代碼生成,并且子項長度超過1頁。

?

打印代碼如下:

PrintDocument _print = new PrintDocument();List<UIElement> uis = new List<UIElement>();_print.PrintPage += (s, e) =>{StackPanel sp = new StackPanel();while (spQues.Children.Count > 0){var ui = spQues.Children[0];spQues.Children.RemoveAt(0);sp.Children.Add(ui);uis.Add(ui);sp.Measure(new Size(e.PrintableArea.Width, double.PositiveInfinity));if (sp.DesiredSize.Height > e.PrintableArea.Height && sp.Children.Count > 1){sp.Children.Remove(ui);uis.Remove(ui);spQues.Children.Insert(0, ui);e.HasMorePages = true;break;}}e.PageVisual = sp;}; _print.EndPrint += (s, e) =>{if (spQues.Children.Count > 0){for (int i = uis.Count() - 1; i >= 0; i--){TextBlock ui = (TextBlock )uis.ElementAt(i); ((StackPanel)ui.Parent).Children.Remove(ui);spQues.Children.Insert(0, ui);}}else{foreach (TextBlock ui in uis){ ((StackPanel)ui.Parent).Children.Remove(ui);spQues.Children.Add(ui);}}uis.Clear();};?

實現的原理就是將StackPanel?"spQues"的子項添加到一個臨時的StackPanel里面,這個臨時的StackPanel一次只增加一頁能夠打印完得內容,如果還有子項未添加完,則指示打印下一頁。在打印完成后將這些子項又加回到原來的StackPanel里。

總結

以上是生活随笔為你收集整理的Silverlight4 多页打印实现的全部內容,希望文章能夠幫你解決所遇到的問題。

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