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

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
aimingoo的专栏
aimingoo的专栏
IT之家
IT之家
N
Netflix TechBlog - Medium
MyScale Blog
MyScale Blog
雷峰网
雷峰网
T
Tailwind CSS Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
The Blog of Author Tim Ferriss
S
Schneier on Security
C
CERT Recently Published Vulnerability Notes
Help Net Security
Help Net Security
云风的 BLOG
云风的 BLOG
GbyAI
GbyAI
I
InfoQ
H
Help Net Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
酷 壳 – CoolShell
酷 壳 – CoolShell
G
GRAHAM CLULEY
Blog — PlanetScale
Blog — PlanetScale
G
Google Developers Blog
I
Intezer
大猫的无限游戏
大猫的无限游戏
AWS News Blog
AWS News Blog
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
Spread Privacy
Spread Privacy
博客园_首页
宝玉的分享
宝玉的分享
量子位
T
Threatpost
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Security Latest
Security Latest
C
Cybersecurity and Infrastructure Security Agency CISA
SecWiki News
SecWiki News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - Franky
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
The Exploit Database - CXSecurity.com
T
Tenable Blog
Know Your Adversary
Know Your Adversary
P
Proofpoint News Feed
The Register - Security
The Register - Security
V2EX - 技术
V2EX - 技术
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Last Week in AI
Last Week in AI
L
LangChain Blog
T
Tor Project blog
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客

博客园 - 奚彧

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