0
該按鈕放置在第二個網格中。第一網格包含我想打印 然而,當我打印第一網格不會顯示任何內容並打印空白文檔網格不打印內容
按鈕和網格代碼:
Button Print = new Button();
Print.Content = "Print";
Print.Click += new RoutedEventHandler(OnPrintClick);
secondGrid.Children.Add(Print);
Grid.SetColumn(Print, 2);
Grid.SetRow(Print, 5);
ColumnDefinition myColumsecondGrid = new ColumnDefinition();
RowDefinition myRowsecondGrid = new RowDefinition();
myRowsecondGrid.Height = new GridLength(300);
myColumsecondGrid.Width = new GridLength(165);
secondGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = myColumsecondGrid.Width });
secondGrid.RowDefinitions.Add(new RowDefinition() { Height = myRow.Height });
按鈕打印代碼:
private void OnPrintClick(object sender, RoutedEventArgs e)
{
PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
if (printDlg.ShowDialog() == true)
{
//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.
myGrid.Measure(sz);
myGrid.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 = "PDF reDirect v2";
System.Printing.PrintQueue queue = new System.Printing.LocalPrintServer().GetPrintQueue(printerName);
printDlg.PrintQueue = queue;
printDlg.PrintVisual(myGrid, "");
}
}