zoukankan      html  css  js  c++  java
  • 关于SilverLight打印(二)

    关于SL打印(二)

    在本页面中有DataGrid数据绑定,可以根据数据加载实现分页打印

    代码
    List<EmployeeModel>() employees = new List<EmployeeModel>();

     
    //调用打印

    GetPrintPage(dataPager1.PageCount, dataPager1.PageSize)
    //当前数据分页中dataPager1
    //当前数据页行数PageSize

    //employees 当前填充DataGrid的集合
    //PageCount总页码
    //Pagesize 每一页页数
    public void GetPrintPage(int PageCount, int Pagesize)
            {
                PrintDocument pd 
    = new PrintDocument();
                
    int itemindex = 0;//从第一张打印
                int count = Pagesize;

                
    //根据页码选择的数据
                pd.PrintPage += (s, pe) =>
                {
                    StackPanel stack 
    = new StackPanel();
                    
    while (itemindex < PageCount)
                    {
                        
    if (itemindex == PageCount- 1)
                        {
                            count 
    = employees.Count - (Pagesize * itemindex);
                        }
                        List
    <EmployeeModel> itemsource = LoadNewList(employees, itemindex * Pagesize, count);

                        PageP mode 
    = new PageP();//当前要打印的页面(包含数据DataGrid)
                        int PrintPageindex = itemindex + 1;
                        mode.MinHeight 
    = 1058;//根据A4纸显示高度
                        mode.dataGrid1.ItemsSource = itemsource;
                        stack.Children.Add(mode);

                        stack.Measure(
    new Size(pe.PrintableArea.Width, double.PositiveInfinity));

                        
    if (stack.DesiredSize.Height > pe.PrintableArea.Height | stack.Children.Count > 1)
                        {
                            stack.Children.Remove(mode);
                            stack.Measure(pe.PrintableArea);
                            pe.HasMorePages 
    = true;
                            
    break;
                        }
                        itemindex 
    += 1;
                    }
                    
                    pe.PageVisual 
    = stack;
                };
                pd.Print(
    null);
            }


    // 获取指定的List集合
      public static List<T> LoadNewList<T>(List<T> _source, int PIndex, int Pcounts)
            {
                List
    <T> newList = new List<T>();

                newList.AddRange(_source.GetRange(PIndex, Pcounts));
                
    return newList;
            }



     附:一般打印都是A4纸;A4纸的标准是宽21cm;高29.7cm.像素为:宽588px;高:862Px;

      一般除开边距margin(70,80,70,80) 余下部分就是可以是datagrid的高度,Pagesize=余下高度/(行高)。

     简单数据分页打印

     如有不足地方,请指出

  • 相关阅读:
    部署时,出现用户代码未处理 System.Security.Cryptography.CryptographicException 错误解决方法
    sqlserver学习笔记(三)—— 为数据库添加新的用户
    [.Net MVC] Win7下IIS部署
    CSS的4种引入方式及优先级
    阿里巴巴图标库全部下载
    div的默认position值是静态的static
    阿里巴巴图标库iconfont上传svg后,显示不了图片
    ext.net单元格内容换行显示
    WEB内容换行
    SQL修改日期类型字段为字符串类型
  • 原文地址:https://www.cnblogs.com/sfwl_1026/p/1896520.html
Copyright © 2011-2022 走看看