如何在没有Datagrid视图的情况下在C#中绘制表格 [英] How Can I Draw Table In C# Without Datagrid View

查看:105
本文介绍了如何在没有Datagrid视图的情况下在C#中绘制表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我需要在c#win forms app中绘制一个报告。但我不允许使用网格或其他控件,我所能做的只是图形绘制。那么任何帮助或建议?桌子很复杂,这里是印刷品。 http://prntscr.com/7hlgbd [ ^ ]

Hello. I need to draw a report in c# win forms app. But i am not allowed to use grids or other controls, all i can do is Graphic drawing. So any help or suggestion? The table is so complex and here is printscreen. http://prntscr.com/7hlgbd[^]

推荐答案

它并不复杂:它仅限于绘图,然后首先设置一个面板(或类似的)绘制并处理它的Paint事件。



然后编写一个采用DataRow和Graphics上下文以及Y偏移量的方法。对DataTable中的每一行重复调用它。



在方法内部,您需要为行中的每个单元格创建RectangleF对象,然后调用 Graphics.DrawText [ ^ ],将RectangleF和单元格内容作为字符串传递给它。试试看:对于固定的表格报告来说,这真的不是那么复杂 - 如果你需要灵活处理细胞数量,大小和位置,或者只是变得复杂文本换行/省略号生成。
It's not complex: It you are limited to Drawing only, then first set up a Panel (or similar) to draw onto, and handle its Paint event.

Then write a method that takes a DataRow and a Graphics context, and a Y offset. Call it repeatedly for each row in the DataTable.

Inside the method you need to create RectangleF objects for each cell in the row and just call Graphics.DrawText[^], passing it the RectangleF and the cell contents as a string.

Try it: It's really not that complex for a "fixed" table report - it only gets complex if you need to be flexible with the cell count, sizes and location, or text wrapping / ellipsis generation.


这篇关于如何在没有Datagrid视图的情况下在C#中绘制表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆