我将如何将下面的代码引用到 c# 中进行打印。我使用资源字典是因为我不想在打印时显示窗口,而是直接从按钮打印。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DockPanel Name="dockpanel" Width="auto" LastChildFill="True" x:Key="Maindock">
<Grid DockPanel.Dock="top" Width="340" >
</DockPanel>
这是打印代码:
//System.Printing
//get selected printer capabilities
System.Printing.PrintCapabilities capabilities =
printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket);
//get the size of the printer page
Size sz = new Size(capabilities.PageImageableArea.ExtentWidth,
capabilities.PageImageableArea.ExtentHeight);
// update the layout of the visual to the printer page size.
Print.Measure(sz);
Print.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth,
capabilities.PageImageableArea.OriginHeight), sz));
//now print the visual to printer to fit on the one page.
//printDlg.PageRangeSelection(printQty);
//now print the visual to printer to fit on the one page.
String printerName = "Brother DCP-7045N Printer";
System.Printing.PrintQueue queue = new System.Printing.LocalPrintServer()
.GetPrintQueueprinterName);
printDlg.PrintQueue = queue;
printDlg.PrintVisual(Print, "");