1 Star 0 Fork 0

携丶七月 / WpfPrintDemo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
MainWindow.xaml.cs 2.52 KB
一键复制 编辑 原始数据 按行查看 历史
崔航周 提交于 2020-08-18 10:42 . 1.支持横向打印
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));
}
}
}
C#
1
https://gitee.com/xieqiyue/WpfPrintDemo.git
git@gitee.com:xieqiyue/WpfPrintDemo.git
xieqiyue
WpfPrintDemo
WpfPrintDemo
master

搜索帮助