WPF:打印带有所有控件的窗口 [英] WPF: Printing a window with all controls

查看:183
本文介绍了WPF:打印带有所有控件的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用内容和WPF屏幕的所有控件打印整个Window,其中还包括可滚动的数据网格.我希望datagrid应该不滚动地打印.我已经尝试过使用流程文档来做到这一点,但没有成功.

非常感谢您的帮助.

I want to print the whole Window with content and all controls of WPF Screen which also includes the scrollable datagrid. I want that the datagrid should be printed without scroll. I have tried it to do this by using flow document but not succeeded.

Any help is greatly appreciated.

推荐答案


我不确定如何取消滚动,但是如果要打印表格,则可以尝试:-

Hi
I am not sure how you can negate the scroll but if you want to print the form then you can try: -

PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
if (printDlg.ShowDialog() == true)
{
      printDlg.PrintVisual(this, "First WPF Print");
}




上面的代码将打印WPF表单,但是如果要打印WPF表单以适合页面,请尝试以下操作:-




The above code will print the WPF form but if you want to print the WPF form to fit the page then try the following: -

PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
if (printDlg.ShowDialog() == true)
   {
      //get selected printer capabilities
      System.Printing.PrintCapabilities capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket);
 
     //get scale of the print wrt to screen of WPF visual
     double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / this.ActualWidth, capabilities.PageImageableArea.ExtentHeight /
                    this.ActualHeight);
 
     //Transform the Visual to scale
     this.LayoutTransform = new ScaleTransform(scale, scale);
 
     //get the size of the printer page
     Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
 
     //update the layout of the visual to the printer page size.
     this.Measure(sz);
     this.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));
 
      //now print the visual to printer to fit on the one page.
      printDlg.PrintVisual(this, "First Fit to Page WPF Print");
 
}



-
AJ



--
AJ


这篇关于WPF:打印带有所有控件的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆