.NET Library for drawing tables with GDI+

元气小坏坏 提交于 2019-12-19 09:38:49

问题


I need to print the contents of a datagridview, simple text in rows and columns, with GDI+ in .NET to paper.

To do this, I need to iterate over the rows, draw lines, iterate over the columns, calculate width, height, wrap the contents if contents do not fit on one line, etc. This is all possible, but is there a library that simplifies the drawing of tables in GDI+ and abstracts some of the difficulties away?


回答1:


This is a very common request. Easy keywords, google "print datagridview". Here's a decent looking one.




回答2:


I've implemented this using XML and XslCompiledTransform.

You need to build your XML (easiest way is using LINQ2XML) and then have your XSLT build the HTML table by enumerating the values your XML produced. You can then represent this in a WebBrowser control, and tell the page to print with WebBrowser.ShowPrintPreviewDialog.

The advantage of using the WebBrowser is having all the page layout tools provided to you so you don't need to worry about it.

Pasting my own implementation would be huge, but please let me know if you need anything clarifying.

Of course, if you have a fixed number of columns, why not try represent it on a report?



来源:https://stackoverflow.com/questions/2990727/net-library-for-drawing-tables-with-gdi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!