<Window x:Class="_096基本打印.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="259" Width="282">
    <Grid Margin="5" Name="grid">
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>
        <Canvas Name="canvas">
            <TextBlock Canvas.Top="50" Canvas.Left="20" FontSize="25" FontWeight="Bold">Hello there</TextBlock>
            <Path Fill="Yellow" Stroke="Blue" Margin="5" Canvas.Left="10">
                <Path.Data>
                    <GeometryGroup>
                        <RectangleGeometry Rect="0 0 100 100"></RectangleGeometry>
                        <EllipseGeometry Center="50 50" RadiusX="35" RadiusY="25"></EllipseGeometry>
                    </GeometryGroup>
                </Path.Data>
            </Path>
        </Canvas>
        <Button Name="btnClick" Grid.Row="1" Click="btnClick_Click_1">Click</Button>
        
    </Grid>

</Window>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Printing;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace _096基本打印
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnClick_Click_1(object sender, RoutedEventArgs e)
        {
            PrintDialog dialog = new PrintDialog();
            var printers = new LocalPrintServer().GetPrintQueues();
            //选择一个打印机
            var selectedPrinter = printers.FirstOrDefault(p => p.Name == "EPSON LQ-300K+ /II ESC/P 2");

            if (selectedPrinter == null)
            {
                MessageBox.Show("没有找到EPSON LQ-300K+ /II ESC/P 2打印机");
                return;
            }

            //设置打印机
            dialog.PrintQueue = selectedPrinter;
            dialog.PrintVisual(canvas, "A Simple Drawing");
            //if (dialog.ShowDialog()==true)
            //{
            //    grid.Visibility = System.Windows.Visibility.Hidden;
            //    canvas.LayoutTransform = new ScaleTransform(5, 5);
            //    int pageMagin = 5;
            //    Size pageSize = new Size(dialog.PrintableAreaWidth - pageMagin * 2, dialog.PrintableAreaHeight - 20);
            //    canvas.Measure(pageSize);
            //    canvas.Arrange(new Rect(pageMagin,pageMagin,pageSize.Width,pageSize.Height));
            //    dialog.PrintVisual(canvas, "A Simple Drawing");
            //    canvas.LayoutTransform = null;
            //    grid.Visibility = System.Windows.Visibility.Visible;
            //}
            
        }
    }
}

WPF 简单打印的更多相关文章

  1. WPF实现打印功能

    WPF实现打印功能 在WPF 中可以通过PrintDialog 类方便的实现应用程序打印功能,本文将使用一个简单实例进行演示.首先在VS中编辑一个图形(如下图所示). 将需要打印的内容放入同一个< ...

  2. WPF备忘录(6)WPF实现打印功能

    在WPF 中可以通过PrintDialog 类方便的实现应用程序打印功能,本文将使用一个简单实例进行演示.首先在VS中编辑一个图形(如下图所示). 将需要打印的内容放入同一个<Canvas> ...

  3. 用WPF实现打印及打印预览

    原文:用WPF实现打印及打印预览 应该说,WPF极大地简化了我们的打印输出工作,想过去使用VC++做开发的时候,打印及预览可是一件极麻烦的事情,而现在我不会再使用C++来做Windows的桌面应用了- ...

  4. WPF简单入门总结

    WPF简单总结 最近看了点关于WPF的东西,总结了点点入门的东西. XAML语法基础 1.  定义样式 <Window.Resources><!--窗体资源的定义--> < ...

  5. wpf 导出Excel Wpf Button 样式 wpf简单进度条 List泛型集合对象排序 C#集合

    wpf 导出Excel   1 private void Button_Click_1(object sender, RoutedEventArgs e) 2 { 3 4 ExportDataGrid ...

  6. C# WPF报表打印

    前天我的一个同学由于打印报表而苦恼,所以就介绍了一下WPF的打印报表,希望能帮助到大家. 展示报表 1. 首先新建项“报表”,选定项目,右击,点击“添加”->“新建项”->“报表”

  7. WPF 流打印

    原文:WPF 流打印 PrintDialog printDialog = new PrintDialog(); if (printDialog.ShowDialog() == true) { Syst ...

  8. .NET CORE(C#) WPF简单菜单MVVM绑定

    微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. .NET CORE(C#) WPF简单菜单MVVM绑定 阅读导航 本文背景 代码实现 本文参考 ...

  9. C# WPF发票打印

    微信公众号:Dotnet9,网站:Dotnet9.问题或建议,请网站留言: 如果您觉得Dotnet9对您有帮助,欢迎赞赏 C# WPF发票打印 内容目录 实现效果 业务场景 编码实现 本文参考 源码下 ...

随机推荐

  1. css选择器指定元素中第几个子元素

    tr td:nth-child(2){ background-color:gray; } 就是tr当中的td的第二个td的属性 tr:nth-child(2n+0){ background-color ...

  2. 关于pptpd log日志文件的配置

    如何开启pptpd默认日志记录功能. 修改/etc/ppp/options.pptpd中的nologfd,默认没有开,把nologfd注释掉,然后添加 logfile /var/log/pptpd.l ...

  3. 开源 RISC-V 架构正在改变 IoT 处理器的游戏规则

    by Paddy McWilliams, Director of Product Marketing, CEVA   在过去的十年里,开源软件已经成为了科技世界最大的催化剂.现在开源的力量带来了自由发 ...

  4. 写bug-free 的code

    一个算法题目 写的没有bug,是件不easy的事情 必需要考虑全面,事实上就是你算法过程中,每一个变量是否适用,你的算法是在什么样的前提以下展开的 这个和參数检查是另外一件事情.參数检查被说的好像是一 ...

  5. uitableview顶部多出20距离, UIScollView顶部多出64距离

    self.automaticallyAdjustsScrollViewInsets = NO;看 这个UIViewController的这个属性你就明白了,此属性默认为YES,这样UIViewCont ...

  6. BZOJ1297 迷路 - 矩阵的幂

    传送门 题目大意: 输入n(点的数量),t(时间),和一个n*n的矩阵,第i行第j列表示第i个节点到第j个节点有一条matrix[i][j](0~9)时间的边,若为0则没有边,问从1到n恰好经过t时间 ...

  7. 检索 04 --Stack栈 Queue队列 Hashtable哈希表

    //Stack 先进后出 没有索引 Stack st = new Stack(); st.Push(12); st.Push(11); st.Push(22); st.Push(34); st.Pus ...

  8. vim note (2)

    :e          edit :edit       edit :e.         edit current file '.'  a dot is means current : w writ ...

  9. 你不从地址栏中增加曝光量所需的数据库ID方法

    <p><span style="font-size: 18px;"></span></p> 当你想隐藏数据库id时,你能够使用 Ha ...

  10. Exclusive access control to a processing resource

    A data processing system is provided with multiple processors that share a main memory. Semaphore va ...