<Window x:Class="_097打印不显示的元素.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="184" Width="269">
    <Grid Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal">
            <Label>Scale Percentage:</Label>
            <TextBox MinWidth="50" Name="txtScale">500</TextBox>
        </StackPanel>
        <Button Grid.Row="1" Name="btnPrint" Click="btnPrint_Click_1">Print</Button>
    </Grid>

</Window>

using System;
using System.Collections.Generic;
using System.Linq;
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 _097打印不显示的元素
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnPrint_Click_1(object sender, RoutedEventArgs e)
        {
            PrintDialog dialog = new PrintDialog();
            if (dialog.ShowDialog() == true)
            {
                Run run = new Run("This is a test of printing function");
                TextBlock visual = new TextBlock();
                visual.Inlines.Add(run);
                visual.Margin = new Thickness(15);
                visual.TextWrapping = TextWrapping.Wrap;
                double zoom;
                if (double.TryParse(txtScale.Text, out zoom))
                {
                    visual.LayoutTransform = new ScaleTransform(zoom / 100, zoom / 100);
                    Size pageSize = new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight);
                    visual.Measure(pageSize);
                    visual.Arrange(new Rect(0, 0, pageSize.Width, pageSize.Height));
                    dialog.PrintVisual(visual, "A Scaled Drawing");
                }
                else
                {
                    MessageBox.Show("Invalid Scale Value");
                }
            }
        }
    }
}

WPF 打印不显示的元素的更多相关文章

  1. 对页面制定区域进行打印,以及打印不显示页脚URL的方法

    第一种方式 - 此种方式简单易用,但不能进行页面设置,会在底部显示页面的URL地址. 打印命令:只需在页面上的按钮事件调用这段JS代码 javascript:window.print(); ===== ...

  2. WPF笔记(1.3 属性元素)——Hello,WPF!

    原文:WPF笔记(1.3 属性元素)--Hello,WPF! 这一节中“属性元素”的概念可以用匪夷所思形容.1.WPF用标签元素实现对象建模,有两种:Control和Container,都用来装载内容 ...

  3. [WPF疑难]ErrorTemplate显示与隐藏问题

    原文:[WPF疑难]ErrorTemplate显示与隐藏问题 [WPF疑难]ErrorTemplate显示与隐藏问题                                         周 ...

  4. jquery可见性选择器(匹配匹配所有显示的元素)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. WPF打印票据

    最近工作的内容是有关于WPF的,整体开发没有什么难度,主要是在打印上因为没有任何经验,犯了一些难,不过还好,解决起来也不是很费劲. WPF打印票据或者是打印普通纸张区别不大,只是说打印票据要把需要打的 ...

  6. ecshop订单打印页显示商品缩略图和序号

    ecshop订单打印页显示商品缩略图和序号 订单打印页显示商品缩略图,在论坛没找到适合2.7.2相关的文章,特意贴上来给大家研究一下.1.找到 $sql = "SELECT o.*, IF( ...

  7. javascript full screen 全屏显示 页面元素

    javascript full screen 全屏显示 页面元素 要想让页面的某个元素全屏显示,就像在网页上看视频的时候,可以全屏观看一样,该怎么实现呢? 一种最简单的方式,就是动态改变你想要全屏显示 ...

  8. AvalonEdit-基于WPF的代码显示控件

    AvalonEdit是基于WPF的代码显示控件,项目地址:https://github.com/icsharpcode/AvalonEdit,支持C#,javascript,C++,XML,HTML, ...

  9. CSS之选择符、链接、盒子模型、显示隐藏元素

    <html> <head> <meta charset="utf-8"> <title>选择符.链接.盒子模型.显示隐藏元素< ...

随机推荐

  1. C# WebAPI中DateTime类型字段在使用微软自带的方法转json格式后默认含T的解决办法

    原文:C# WebAPI中DateTime类型字段在使用微软自带的方法转json格式后默认含T的解决办法 本人新手,在.Net中写WebAPI的时候,当接口返回的json数据含有日期时间类型的字段时, ...

  2. 【40.17%】【codeforces 569B】Inventory

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. Effective Java读书笔记——第三章 对于全部对象都通用的方法

    第8条:覆盖equals时请遵守通用的约定 设计Object类的目的就是用来覆盖的,它全部的非final方法都是用来被覆盖的(equals.hashcode.clone.finalize)都有通用约定 ...

  4. [Compose] 16. Apply multiple functors as arguments to a function (Applicatives)

    We find a couple of DOM nodes that may or may not exist and run a calculation on the page height usi ...

  5. SPOJ4491. Primes in GCD Table(gcd(a,b)=d素数,(1&lt;=a&lt;=n,1&lt;=b&lt;=m))加强版

    SPOJ4491. Primes in GCD Table Problem code: PGCD Johnny has created a table which encodes the result ...

  6. [转] Valgrind使用

    http://www.cnblogs.com/napoleon_liu/articles/2001802.html 调不尽的内存泄漏,用不完的Valgrind Valgrind 安装 1. 到www. ...

  7. Freemarker中的日期转换

    1. 把数字类型表示的日期,转换成datetime类型,字符串输出.${item.time?number_to_datetime},默认的格式是"yyyy-MM-dd hh:mm:ss&qu ...

  8. TensorFlow 学习(十三)—— tf.app.flags

    flags = tf.app.flags FLAGS = flags.FLAGS flags.DEFINE_integer('num_hidden_layers', 3, 'number of hid ...

  9. 云平台DevOps实践

    基于TFS的.net技术路线的云平台DevOps实践   DevOps是近几年非常流行的系统研发管理模式,很多公司都或多或少在践行DevOps.那么,今天就说说特来电云平台在DevOps方面的实践吧. ...

  10. 使用python抓取CSDN关注人的全部公布的文章

    # -*- coding: utf-8 -*- """ @author: jiangfuqiang """ import re import ...