首页 > Windows开发 > 详细

WPF打印控件内容

时间:2017-08-10 19:14:12      阅读:289      评论:0      收藏:0      [点我收藏+]

当我们想打印控件内容时,如一个Grid中的内容,可以用WPF中PrintDialog类的PrintVisual()方法来实现

界面如下:

技术分享

XAML代码如下

 1  <Grid>
 2         <Grid.ColumnDefinitions>
 3             <ColumnDefinition/>
 4             <ColumnDefinition Width="300"/>
 5         </Grid.ColumnDefinitions>
 6         <Grid Grid.Column="0">
 7 
 8             <Grid Width="800" Name="grid1">
 9                 <TextBlock TextWrapping="Wrap" FontSize="15">
10                 Control authors who want to customize the arrange pass of layout processing should override this method. The implementation pattern should call M:System.Windows.UIElement.Arrange(System.Windows.Rect) on each visible child element, and pass the final desired size for each child element as the finalRect parameter. Parent elements should call M:System.Windows.UIElement.Arrange(System.Windows.Rect) on each child, otherwise the child elements will not be rendered.
11 Many derived classes offer implementations of this method. Prominent ones include: M:System.Windows.Window.ArrangeOverride(System.Windows.Size), M:System.Windows.Controls.Page.ArrangeOverride(System.Windows.Size) and M:System.Windows.Controls.Control.ArrangeOverride(System.Windows.Size).
12                 </TextBlock>
13             </Grid>
14         </Grid>
15       
16         <Grid Grid.Column="1">
17             <Button Height="30" VerticalAlignment="Top" Click="Button_Click">打印</Button>
18         </Grid>
19     </Grid>

当我们点击按钮时,进行打印

按钮事件:

 

WPF打印控件内容

原文:http://www.cnblogs.com/zhaotianff/p/7340554.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!