1
private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog dialog = new PrintDialog();
            if (dialog.ShowDialog() == true)
            {
                StackPanel stpanel;
                stpanel = PrintStakPanel;
                stpanel.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                Size grdSize = stpanel.DesiredSize;
                Point grdPoint = new Point((dialog.PrintableAreaWidth - grdSize.Width) / 2, (dialog.PrintableAreaHeight - grdSize.Height) / 2);
                stpanel.Arrange(new Rect(grdPoint, grdSize));
                Grid.SetRow(stpanel, 0);
                dialog.PrintVisual(stpanel, "Cinema Ticket");

            }
        }
4

2 回答 2

1

不要在代码中调用 dialog.ShowDialog()。

于 2012-10-31T14:21:21.237 回答
1

PrintDialog无需ShowDialog()拨打电话即可使用....当前设置的打印机设置将仅在您拨打电话时使用PrintVisual

要执行更复杂的操作,您可以使用PrintTicket.

有关更多详细信息,请参见此处:

于 2012-10-31T12:40:04.693 回答