如何打印一个TreeView



我想打印当用户点击打印按钮时显示在树视图中的数据使用"打印文档"并将其打印在实际纸张上我使用的是Visual Studio 2008

试试这些链接是否有帮助:

http://bytes.com/topic/c-sharp/answers/886644-printing-treeview

https://stackoverflow.com/questions/5602383/want-to-print-data-in-treeview-in-c

创建内存中的TreeView,然后复制重要属性并转移根节点。之后,在内存中创建一个位图,并通过DrawToBitmap函数绘制Treeview内容,在页面上绘制图像并将根节点恢复到原始位置。

    private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        var memtree = new TreeView();
        var rn = treeView1.Nodes[0];
        treeView1.Nodes.Remove(rn);
        memtree.ImageList = treeView1.ImageList;
        memtree.BorderStyle = BorderStyle.None;
        memtree.Nodes.Add(rn);
        memtree.ClientSize = new Size(e.MarginBounds.Width, e.MarginBounds.Height);
        var bmp = new Bitmap(e.MarginBounds.Width, e.MarginBounds.Height);
        memtree.DrawToBitmap(bmp, new Rectangle(0, 0, e.MarginBounds.Width-1, e.MarginBounds.Height-1));
        e.Graphics.DrawImage(bmp, e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width -1, e.MarginBounds.Height -1);
        memtree.Nodes.Remove(rn);
        treeView1.Nodes.Add(rn);
    }

相关内容

  • 没有找到相关文章

最新更新