如何显示窗口的原始大小的一半

本文关键字:原始 一半 窗口 何显示 显示 | 更新日期: 2023-09-27 18:03:23

我正在打印一个A4的WPF窗口,所以原来窗口的大小相当大。我想在不修改打印输出的情况下,将其显示为原始尺寸的一半。什么好主意吗?

这是我打印

的方法
private void printItemList(string printerName)
    {
        //printButton.Visibility = Visibility.Collapsed;
        //cancelButton.Visibility = Visibility.Collapsed;
        PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
        printDlg.PrintQueue = new System.Printing.PrintQueue(new System.Printing.PrintServer(), printerName);
        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(this.ActualWidth, this.ActualHeight); //(8.5 * 96.0, 11.0 * 96.0);
        //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, "Print Page");
        this.DialogResult = true;
    }

如何显示窗口的原始大小的一半

ViewBox做什么我在想,我只需要确保它是打印执行前调整大小。谢谢你的提示。