Userdefined margins in WPF printing
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 myIm开发者_Go百科age = 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
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.
精彩评论