码迷,mamicode.com
首页 > 其他好文 > 详细

GridView直接打印

时间:2018-11-14 18:51:44      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:color   links   margin   raw   datetime   component   tle   summary   ted   

/// <summary>
        /// 打印功能
        /// </summary>
        /// <param name="panel">打印控件</param>
        /// <param name="title">标题</param>
        /// <param name="pageSize">纸张类型</param>
        /// <param name="margins">边距</param>
        public virtual void Print(IPrintable panel,string title = null, PaperKind pageSize = PaperKind.A4, System.Drawing.Printing.Margins margins = null)
        {
            PrintingSystem ps = new PrintingSystem();
            CompositeLink link = new CompositeLink(ps);
            PrintableComponentLink printableLink = new PrintableComponentLink() { Component = panel };
            ps.Links.Add(link);
            link.Links.Add(printableLink);
            //link.Landscape = false;//横向
            link.PaperKind = pageSize;//设置纸张大小
            if (margins == null)
                margins = new System.Drawing.Printing.Margins(0, 0, 10, 10);
            link.Margins = margins;
            ////判断是否有标题,有则设置
            //if (!string.IsNullOrEmpty(title))
            //{

            //    PageHeaderFooter phf = link.PageHeaderFooter as PageHeaderFooter;
            //    phf.Header.Content.Clear();
            //    phf.Header.Content.AddRange(new string[] { "", title, "" });
            //    phf.Header.Font = new System.Drawing.Font("宋体", 14, System.Drawing.FontStyle.Bold);
            //    phf.Header.LineAlignment = BrickAlignment.Center;

            //    //phf.Footer.Content.AddRange(new string[] { "", String.Format("打印时间: {0:g}", DateTime.Now), "" });
            //}
            link.CreateDocument(); //建立文档
            //ps.PreviewRibbonFormEx.Show();//进行预览 
            ps.Print();
        }

 

GridView直接打印

标签:color   links   margin   raw   datetime   component   tle   summary   ted   

原文地址:https://www.cnblogs.com/shuaimeng/p/9959176.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!