惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
V2EX - 技术
V2EX - 技术
Jina AI
Jina AI
有赞技术团队
有赞技术团队
美团技术团队
月光博客
月光博客
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 三生石上(FineUI控件)
V
V2EX
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
人人都是产品经理
人人都是产品经理
Security Latest
Security Latest
C
CERT Recently Published Vulnerability Notes
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享
罗磊的独立博客
J
Java Code Geeks
博客园 - Franky
V
Vulnerabilities – Threatpost
C
CXSECURITY Database RSS Feed - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
小众软件
小众软件
P
Privacy & Cybersecurity Law Blog
量子位
T
Threatpost
T
Tailwind CSS Blog
V
Visual Studio Blog
C
Cisco Blogs
雷峰网
雷峰网
博客园 - 【当耐特】
T
Tor Project blog
T
The Exploit Database - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园_首页
H
Heimdal Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - 聂微东
爱范儿
爱范儿
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Threat Research - Cisco Blogs
T
Troy Hunt's Blog
H
Hacker News: Front Page
T
Tenable Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint

博客园 - 奚彧

Siverlight 导出Excel (经测试通过 Vs2010 ,silverlight5 ) 部署silverlight ria 程序 备忘 刚学 silverlight 问题遇到一堆 2010 微软难道抛弃了ado.net data service openfire 安装 关于DataSet.merge 问题的答案。 关于merge .net常用代码 (收藏) - 奚彧 - 博客园 碰到一个巨郁闷的情况! - 奚彧 - 博客园 关于连接池问题 删除确认按钮 - 奚彧 - 博客园 水晶报表自动插入空白行 也谈如何缩小SQL SERVER日志文件 新年第一帖,祝大家新年快乐! vs2005什么时候能出正式版 《WEB打印的相关技术分析》 web打印2 web打印 权限设置问题!(比较着急)
打印代码片段
奚彧 · 2013-10-05 · via 博客园 - 奚彧
//当前打印的行的索引,用于遍历ListBox.Items
        private int listPrintIndex;
        private void btnPrintList_Click(object sender, RoutedEventArgs e)
        {
            //初始值为0
            listPrintIndex = 0;
            PrintDocument document = new PrintDocument();
            document.PrintPage += new EventHandler<PrintPageEventArgs>(document_PrintPage);
            document.Print("Print List");
        }

        //设置每一项之间的间距
        private int extraMargin = 50;
        void document_PrintPage(object sender, PrintPageEventArgs e)
        {
            //定义一个打印的元素
            Canvas printSurface = new Canvas();
            e.PageVisual = printSurface;
            //得到最顶端位置
            double topPosition = e.PageMargins.Top + extraMargin;

            //遍历当前的ListBox.Items
            while (listPrintIndex<lstPrint.Items.Count)
            {
                //实例化TextBlock用来存放ListItem的值
                TextBlock txt = new TextBlock();
                txt.FontSize = 30;
                //得到ListBox每一项的值
                txt.Text = lstPrint.Items[listPrintIndex].ToString();
                double measuredHeight = txt.ActualHeight;
                //如果打印的当前行高度不合适的话,则进行分页
                if (measuredHeight>(e.PrintableArea.Height- topPosition- extraMargin))
                {
                    e.HasMorePages = true;
                    return ;
                }

                //设置TextBlock在Canvas中的位置
                txt.SetValue(Canvas.TopProperty, topPosition);
                txt.SetValue(Canvas.LeftProperty, e.PageMargins.Left + extraMargin);
                //将TextBlock添加到打印的元素中去
                printSurface.Children.Add(txt);

                listPrintIndex++;
                //追加高度
                topPosition = topPosition + measuredHeight;
            }
            e.HasMorePages = false;
        }