PrintVisual无法在Windows 7上运行

时间:2016-09-02 18:17:29

标签: c# wpf printing

我需要使用PrintVisual函数打印一份小报告,如下所示:

uc.DataContext = myDataTable.DefaultView; // us is UserControl
PrintDialog pDialog = new PrintDialog();
pDialog.PageRangeSelection = PageRangeSelection.AllPages;
pDialog.UserPageRangeEnabled = true;
pDialog.PrintQueue = System.Printing.LocalPrintServer.GetDefaultPrintQueue();
pDialog.PrintTicket = pDialog.PrintQueue.DefaultPrintTicket;
pDialog.PrintTicket.PageScalingFactor = 1;

System.Printing.PrintCapabilities capabilities = null;
try
{
    capabilities = pDialog.PrintQueue.GetPrintCapabilities();
}
catch
{
    capabilities = null;
}
Viewbox vb = new Viewbox();
vb.Child = uc;

System.Windows.Size sz = new Size(520, 380);
vb.MinWidth = 1;
vb.MinHeight = 1;
vb.Measure(sz);
vb.Arrange(new System.Windows.Rect(new System.Windows.Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

double scale = 1;
vb.LayoutTransform = new ScaleTransform(scale, scale);

pDialog.PrintVisual(vb, "MyViewBox");

代码在Win 8中运行良好并且赢得10但在win 7上没有 有什么建议吗?

0 个答案:

没有答案