簡體   English   中英

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

[英]How to display a window half of its original size

我正在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可以實現我的想法,我只需要確保在執行打印之前調整其大小即可。 謝謝你的提示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM