当前位置: 首页 > wzjs >正文

哪个网站做音基的题不花钱金本网站建设设计

哪个网站做音基的题不花钱,金本网站建设设计,如皋电子商城网站建设,濮阳网站建设熊掌号DataGrid 是 .NET 架构中一个功能极其丰富的组件,或许也是最复杂的组件之一。写这篇文章是为了回答“我到底该如何打印 DataGrid 及其内容”这个问题。最初即兴的建议是使用我的屏幕截图文章来截取表单,但这当然无法解决打印 DataGrid 中虚拟显示的无数行…

        DataGrid 是 .NET 架构中一个功能极其丰富的组件,或许也是最复杂的组件之一。写这篇文章是为了回答“我到底该如何打印 DataGrid 及其内容”这个问题。最初即兴的建议是使用我的屏幕截图文章来截取表单,但这当然无法解决打印 DataGrid 中虚拟显示的无数行数据的问题。后来想了想,这应该很简单,我只需使用 GDI+ 遍历 DataGrid 中的行并打印其内容即可。其实,DataGrid 比这更复杂一些,因为它本身并不包含数据。数据包含在 DataSet 中。因此,最终确定的方法是从 DataGrid 中捕获颜色和字体属性用于打印输出,并从 DataSet 中捕获行中的信息。为了将 DataGridPrinter 的绘制功能封装到 Printer 中,我创建了 DataGridPrinter 类,如下图 2 所示。此类将 DataGrid、PrintDocument 和 DataTable 传递给其构造函数,并利用这些对象将 DataGrid 绘制到打印机。

图 1. Northwind DataGrid 的打印预览

图 2. DataGridPrinter 类 UML 设计(使用 WithClass 2000 进行逆向工程)

        DataGridPrinter 在表单的构造函数中构建,因此它可以被所有打印功能(打印、打印预览等)使用。下面是构建 DataGridPrinter 的代码:

void SetupGridPrinter()  
{  
    dataGridPrinter1 =new DataGridPrinter(dataGrid1, printDocument1,  
    dataSet11.Customers);  
}  

一旦构建了 DataGridPrinter,您就可以通过在 Print Page 事件处理程序中调用其 DrawDataGrid 方法将 DataGrid 绘制到打印机上:

private void printDocument1_PrintPage(object sender,System.Drawing.Printing.PrintPageEventArgs e)  
{  
    Graphics g = e.Graphics;  
    // Draw a label title for the grid  
    DrawTopLabel(g);  
    // draw the datagrid using the DrawDataGrid method passing the Graphics surface  
    bool more = dataGridPrinter1.DrawDataGrid(g);  
    // if there are more pages, set the flag to cause the form to trigger another print page event  
    if (more == true)  
    {  
        e.HasMorePages =true;  
        dataGridPrinter1.PageNumber++;  
    }  
}  

        PrintPage 事件由 PrintDocument 中的 Print 方法和 PrintPreviewDialog 的 ShowDialog 方法触发。下面是窗体将 DataGrid 打印到打印机的方法:

private void PrintMenu_Click(object sender, System.EventArgs e)  
{  
    // Initialize the datagrid page and row properties  
    dataGridPrinter1.PageNumber = 1;  
    dataGridPrinter1.RowCount = 0;  
    // Show the Print Dialog to set properties and print the document after ok is pressed.  
    if (printDialog1.ShowDialog() == DialogResult.OK)  
    {  
        printDocument1.Print();  
    }  
}  

        现在让我们来看看 DataGridPrinter 方法的内部实现。DataGridPrinter 类中有两个主要方法用于执行所有绘制操作:DrawHeader 和 DrawRows。这两个方法都从 DataGrid 和 DataTable 中提取信息来绘制 DataGrid。以下是绘制 DataGrid 行的方法:

public bool DrawRows(Graphics g)  
    {  
        try  
        {  
            int lastRowBottom = TopMargin;  
            // Create an array to save the horizontal positions for drawing horizontal gridlines  
            ArrayList Lines = new ArrayList();  
            // form brushes based on the color properties of the DataGrid  
            // These brushes will be used to draw the grid borders and cells  
            SolidBrush ForeBrush = new SolidBrush(TheDataGrid.ForeColor);  
            SolidBrush BackBrush = new SolidBrush(TheDataGrid.BackColor);  
            SolidBrush AlternatingBackBrush = new SolidBrush  
            TheDataGrid.AlternatingBackColor);  
            Pen TheLinePen = new Pen(TheDataGrid.GridLineColor, 1);  
            // Create a format for the cell so that the string in the cell is cut off at the end of  
            the column width  
            StringFormat cellformat = new StringFormat();  
            cellformat.Trimming = StringTrimming.EllipsisCharacter;  
            cellformat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit;  
            // calculate the column width based on the width of the printed page and the # of  
            columns in the DataTable  
            // Note: Column Widths can be made variable in a future program by playing with the GridColumnStyles of the  
            // DataGrid  
            int columnwidth = PageWidth / TheTable.Columns.Count;  
            // set the initial row count, this will start at 0 for the first page, and be a different  
            value for the 2nd, 3rd, 4th, etc.  
            // pages.  
            int initialRowCount = RowCount;  
            RectangleF RowBounds = new RectangleF(0, 0, 0, 0);  
            // draw the rows of the table   
            for (int i = initialRowCount; i < TheTable.Rows.Count; i++)  
            {  
                // get the next DataRow in the DataTable  
                DataRow dr = TheTable.Rows[i];  
                int startxposition = TheDataGrid.Location.X;  
                // Calculate the row boundary based on teh RowCount and offsets into the page  
                RowBounds.X = TheDataGrid.Location.X; RowBounds.Y = TheDataGrid.Location.Y +  
                 TopMargin + ((RowCount - initialRowCount) + 1) * (TheDataGrid.Font.SizeInPoints +  
                 kVerticalCellLeeway);  
                RowBounds.Height = TheDataGrid.Font.SizeInPoints + kVerticalCellLeeway;  
                RowBounds.Width = PageWidth;  
                // save the vertical row positions for drawing grid lines  
                Lines.Add(RowBounds.Bottom);  
                // paint rows differently for alternate row colors  
                if (i % 2 == 0)  
                {  
                    g.FillRectangle(BackBrush, RowBounds);  
                }  
                else  
                {  
                    g.FillRectangle(AlternatingBackBrush, RowBounds);  
                }  
                // Go through each column in the row and draw the information from the  
                DataRowfor(int j = 0; j < TheTable.Columns.Count; j++)  
                {  
                RectangleF cellbounds = new RectangleF(startxposition,  
                TheDataGrid.Location.Y + TopMargin + ((RowCount - initialRowCount) + 1) *  
                (TheDataGrid.Font.SizeInPoints + kVerticalCellLeeway),  
                columnwidth,  
                TheDataGrid.Font.SizeInPoints + kVerticalCellLeeway);  
                // draw the data at the next position in the row  
                if (startxposition + columnwidth <= PageWidth)  
                {  
                    g.DrawString(dr[j].ToString(), TheDataGrid.Font, ForeBrush, cellbounds, cellformat);  
                    lastRowBottom = (int)cellbounds.Bottom;  
                }  
                // increment the column position  
                startxposition = startxposition + columnwidth;  
            }  
            RowCount++;  
            // when we've reached the bottom of the page, draw the horizontal and vertical grid lines and return true  
        if (RowCount * (TheDataGrid.Font.SizeInPoints + kVerticalCellLeeway) >  
        PageHeight * PageNumber) - (BottomMargin + TopMargin))  
            {  
                DrawHorizontalLines(g, Lines); DrawVerticalGridLines(g, TheLinePen, columnwidth,  
                 lastRowBottom);  
                return true;  
            }  
        }  
// when we've reached the end of the table, draw the horizontal and vertical gridlines and return false  
    DrawHorizontalLines(g, Lines);  
    DrawVerticalGridLines(g, TheLinePen, columnwidth, lastRowBottom);  
    return false;  
}  
catch (Exception ex)  
{  
MessageBox.Show(ex.Message.ToString());  
return false;  
}  

        该方法遍历 DataTable 中的每一行并绘制数据。该方法使用 DataGrid 的属性,用适当的颜色绘制每一行,并使用 DataGrid 的字体绘制每个字符串。如果该方法到达页面底部,则会中断并返回 true,以便将 DataGrid 的剩余部分打印到下一页。

改进:

利用         DataGrid 的 TableStyles 属性中存储的 DataGridColumnStyle 类,可以极大地改进此类。这些属性允许您为某些列指定不同的列宽以及不同的文本对齐方式。

如果您喜欢此文章,请收藏、点赞、评论,谢谢,祝您快乐每一天。 


文章转载自:

http://g2DXkRNE.tsyny.cn
http://Lf5pMVJW.tsyny.cn
http://QfhjPxaH.tsyny.cn
http://0lo2f9XK.tsyny.cn
http://Lot3hhaY.tsyny.cn
http://sAr1HLGR.tsyny.cn
http://pYl9M64S.tsyny.cn
http://7aSy7vnA.tsyny.cn
http://fzOxttTv.tsyny.cn
http://YdlbHem4.tsyny.cn
http://uHLtOJnO.tsyny.cn
http://uGwNQEiA.tsyny.cn
http://xYGQO8aO.tsyny.cn
http://9T8E6XCp.tsyny.cn
http://5VvqpV3v.tsyny.cn
http://dCI7kgaZ.tsyny.cn
http://ZwobSJTo.tsyny.cn
http://7WaEX96Z.tsyny.cn
http://aFd8Tw0T.tsyny.cn
http://gHEFFC5a.tsyny.cn
http://3N74o6RL.tsyny.cn
http://5HrfwNEY.tsyny.cn
http://b8e4Dgik.tsyny.cn
http://9lBsYgxp.tsyny.cn
http://nscdEV0Z.tsyny.cn
http://E2Ep1vO5.tsyny.cn
http://95V8ifLn.tsyny.cn
http://1lh5JOw1.tsyny.cn
http://TB2tvtjj.tsyny.cn
http://wsmJY1dv.tsyny.cn
http://www.dtcms.com/wzjs/751838.html

相关文章:

  • 制作单网页网站网站可行性分析
  • 网站建设品牌推荐邵阳建设银行网站是多少
  • 哈尔滨企业建站网站开发企业做网站公司
  • 本地化吃喝玩乐平台网站可以做吗app开发商城
  • 小说投稿赚钱的网站怎么做网站免费的教程
  • 快速网站建设旅游电子商务网站策划书
  • 提供网站建设设计公司排名公司网站后台维护怎么做
  • 制作网站的收获体会网站备案 的类型
  • 电商网站前端架构设计厦门有家装饰
  • 工程招聘网站延安网站建设报价
  • 潍坊市安丘建设局网站宁波网站建设工作室
  • 长沙做网站最好的公司有哪些外卖网站建设可行性分析
  • 无锡游戏网站建设公司wordpress免费 主题
  • 嘉兴网站如何制作wordpress 搭建app
  • 网站设计师专业邯郸网络安装
  • 太平阳电脑网网站模板小程序开发需要多少钱?
  • 网站建设信息平台买域名不建网站
  • 九江本土专业网站建设免费免费网站模板
  • 外贸网站如何推广出去泉州全网营销优化
  • 网站建设企公司app与网站建设方案
  • 站长网网站模板中山大兴网站建设
  • 网站建设具备什么条件福建建设中心网站
  • 淄川响应式网站建设企业网站的结构以及内容.
  • 淘宝客网站要多大空间网站做兼容处理怎么设置
  • 用什么软件做购物网站做定制网站怎么样
  • 做网站公司排行网站开发的有关公司
  • 可以看网站的手机浏览器珠海微信网站开发
  • 腾讯做网站上传wordpress二级菜单代码
  • 网站建设费用上海北京市建筑网站
  • 护肤品网站建设需求分析企业宣传册模板