代码拉取完成,页面将自动刷新
using System;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Threading;
namespace WpfPrintDemo
{
public partial class MainWindow : Window
{
private delegate void DoPrintMethod(PrintDialog pdlg, DocumentPaginator paginator);
private delegate void EnableButtonMethod();
private Timer m_timerToEnableButton;
private void DoPrint(PrintDialog pdlg, DocumentPaginator paginator)
{
pdlg.PrintDocument(paginator, "Order Document");
}
private void EnableButton()
{
btnPrintDirect.IsEnabled = true;
}
public MainWindow()
{
InitializeComponent();
}
private void btnPrintPreview_Click(object sender, RoutedEventArgs e)
{
OrderDocument tempView = new OrderDocument();
PrintPreviewWin previewWnd = new PrintPreviewWin(tempView, GlobalData.m_orderExample, new OrderDocumentRenderer());
previewWnd.Owner = this;
previewWnd.ShowInTaskbar = false;
previewWnd.ShowDialog();
}
private void btnPrintDlg_Click(object sender, RoutedEventArgs e)
{
PrintDialog pdlg = new PrintDialog();
if (pdlg.ShowDialog() == true)
{
OrderDocument tempView = new OrderDocument();
FlowDocument doc = PrintPreviewWin.LoadViewAndData(tempView, GlobalData.m_orderExample, new OrderDocumentRenderer());
Dispatcher.BeginInvoke(new DoPrintMethod(DoPrint), DispatcherPriority.ApplicationIdle, pdlg, ((IDocumentPaginatorSource)doc).DocumentPaginator);
}
}
private void btnPrintDirect_Click(object sender, RoutedEventArgs e)
{
btnPrintDirect.IsEnabled = false;
PrintDialog pdlg = new PrintDialog();
OrderDocument tempView = new OrderDocument();
FlowDocument doc = PrintPreviewWin.LoadViewAndData(tempView, GlobalData.m_orderExample, new OrderDocumentRenderer());
Dispatcher.BeginInvoke(new DoPrintMethod(DoPrint), DispatcherPriority.ApplicationIdle, pdlg, ((IDocumentPaginatorSource)doc).DocumentPaginator);
m_timerToEnableButton = new Timer(TestTimerCallback, null, 3000, Timeout.Infinite);
}
public void TestTimerCallback(object state)
{
m_timerToEnableButton.Dispose();
Dispatcher.BeginInvoke(new EnableButtonMethod(EnableButton));
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。