2
我试图从我的wpf应用程序打印出一些信息。我找到了一些代码来制作我想要打印的内容以适合一个页面,并且它很好地完成了这项工作。问题是,在打印我想要的内容后,该方法会缩小我的wpf控件,这是一个带有图表的组合框。我如何将groupbox的大小缩放到缩放前的大小?打印缩放我的WPF-GroupBox
private void PrintUT_Click(object sender, RoutedEventArgs e)
{
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.GBProsjektTimer.ActualWidth, capabilities.PageImageableArea.ExtentHeight/
this.GBProsjektTimer.ActualHeight);
//Transform the Visual to scale
this.GBProsjektTimer.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.GBProsjektTimer, "First Fit to Page WPF Print");
}
}
感谢您花时间发布您自己的答案。如果能够这样做,请接受它 - 这可以让其他人知道已找到解决方案。谢谢,欢迎来到SO。 – Basic 2013-04-05 13:15:33