zoukankan      html  css  js  c++  java
  • WPF 简单打印

    <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;
                //}
                
            }
        }
    }

  • 相关阅读:
    【bzoj2115】[Wc2011] Xor
    【bzoj2460】[BeiJing2011]元素
    P2300 合并神犇 DP
    P1041 传染病控制 深搜
    P1038 神经网络 图论
    树状数组模板
    送外卖 状压DP
    士兵守卫(同P2016 战略游戏) 树形DP
    P1171 售货员的难题 喻队状压 DP
    P2062 分队问题 DP
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434783.html
Copyright © 2011-2022 走看看