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