网格未打印内容
本文关键字:打印 网格 | 更新日期: 2023-09-27 18:20:44
按钮位于第二个网格中。第一个网格包含我要打印的内容然而,当我打印第一个网格时,它没有显示任何内容,并且正在打印一个空白文档
按钮和网格代码:
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, "");
}
}
也许这个问题会对你有所帮助。你可以看看Measure和Arrange方法,可能在里面。
打印在wpf 中动态生成的网格
这段代码为您打印了什么吗?如果是这样的话,那就说明测量结果有问题。另外,不要忘记,在您尝试使用PrintVisual方法打印网格时,必须对其进行渲染。
PrintDialog dialog = new PrintDialog();
if (dialog.ShowDialog() == true)
{
dialog.PrintVisual(myGrid, "CustomDescription");
}