WPF 打印中用户定义的边距
大多数 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相当确定您在
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.