2011-03-01 74 views
2

大多数印刷样品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 迈克尔

回答

0

我相当确信,你是在PrintDialog改变保证金的打印机驱动程序特定的设置。您无法从.NET访问设置是正常的。

+0

我找到了一个解决方案: PrintDocumentImageableArea area = null;XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(ref area); 边距位于区域对象中。 但是,这总是打开打印对话框,也许我找到了一些方法来获得默认边距,而无需打开对话框。 – MTR 2011-03-03 15:30:17