码迷,mamicode.com
首页 > Windows程序 > 详细

WPF打印控件内容

时间:2017-08-10 19:41:35      阅读:363      评论:0      收藏:0      [点我收藏+]

标签:include   技术分享   auth   wrap   fonts   override   vertica   visible   app   

当我们想打印控件内容时,如一个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打印控件内容

标签:include   技术分享   auth   wrap   fonts   override   vertica   visible   app   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!