WPF 打印中用户定义的边距

发布于 2024-10-19 19:58:31 字数 912 浏览 9 评论 0原文

大多数 WPF 打印示例都是这样的:

        PrintDialog dialog = new PrintDialog();
        if (dialog.ShowDialog() == true)
        {
           StackPanel myPanel = new StackPanel();
           myPanel.Margin = new Thickness(15);
           Image myImage = new Image();
           myImage.Width = dialog.PrintableAreaWidth;
           myImage.Stretch = Stretch.Uniform;
           myImage.Source = new BitmapImage(new Uri("pack://application:,,,/Images/picture.bmp"));
           myPanel.Children.Add(myImage);
           myPanel.Measure(new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight));
           myPanel.Arrange(new Rect(new Point(0, 0), myPanel.DesiredSize));
           dialog.PrintVisual(myPanel, "A Great Image.");
        }

我不喜欢的是,它们总是将边距设置为固定值。 但在 PrintDialog 中,用户可以选择没有样本关心的单独边距。如果用户现在选择的边距大于程序设置的固定边距,则打印输出将被截断。 有没有办法从 PrintDialog 获取用户选择的边距值?

TIA 迈克尔

Most printing samples for WPF go like this:

        PrintDialog dialog = new PrintDialog();
        if (dialog.ShowDialog() == true)
        {
           StackPanel myPanel = new StackPanel();
           myPanel.Margin = new Thickness(15);
           Image myImage = new Image();
           myImage.Width = dialog.PrintableAreaWidth;
           myImage.Stretch = Stretch.Uniform;
           myImage.Source = new BitmapImage(new Uri("pack://application:,,,/Images/picture.bmp"));
           myPanel.Children.Add(myImage);
           myPanel.Measure(new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight));
           myPanel.Arrange(new Rect(new Point(0, 0), myPanel.DesiredSize));
           dialog.PrintVisual(myPanel, "A Great Image.");
        }

What I don't like about this is, that they always set the margin to a fixed value.
But in PrintDialog the user has the option to choose a individual margin that no sample cares about. If the user now selects a margin that is larger as the fixed margin set by program, the printout is truncated.
Is there a way to get the user selected margin value from PrintDialog?

TIA
Michael

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦醒灬来后我 2024-10-26 19:58:31

我相当确定您在 PrintDialog 中更改的边距是打印机驱动程序特定的设置。您无法从 .NET 访问该设置是正常的。

I am fairly sure that the margin that you are changing in the PrintDialog is a printer driver-specific setting. It's normal that you cannot access the setting from .NET.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文