简体   繁体   English

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

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

I'm printing a WPF window in A4, so originally the window size is rather big. 我正在A4中打印WPF窗口,因此最初的窗口大小很大。 I would like to display it half the size of the original without modifying the printing output. 我想将其显示为原始尺寸的一半,而不修改打印输出。 Any ideas? 有任何想法吗?

This is my method where I print 这是我打印的方法

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 does what I was thinking, I just have to make sure it is resized before printing executed. ViewBox可以实现我的想法,我只需要确保在执行打印之前调整其大小即可。 Thanks for the tip. 谢谢你的提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 Window 脱钩到原来的 State - Unhook Window into its original State 如何自动调整窗口大小以适合其内容 - How to automatically size a Window to fit its content 如何将图像绘制为pdf并仍保持其原始大小? - How to draw image to pdf and still maintain its original size? 如何将更改后的文本显示为原始文本几秒钟? - How to display changed text for few seconds from its original text? 如何在图像控件中显示图像的原始大小 - How to display image it's original size in Image control 如何获得与窗口大小成比例显示的图像? - How can I get images to display in proportion to the size of the window? 为什么在粘贴到 Excel 时图像显示的大小大于其实际大小,我如何才能使其以自然大小显示? - Why does an image display at greater that its actual size when pasting into Excel, and how can I get it to display at its natural size? 如何将WPF窗口嵌入另一个窗口并通过XAML或代码调整其大小 - How to embed WPF Window into another Window and adjust its size via XAML or code 按下按钮将WPF窗口重置为其原始状态(启动) - Reset WPF window to its original state(startup) with a press of a button 根据窗口的内部内容定义窗口的大小 - Define the size of a window based on its inner content
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM