c# - System.Drawing.Graphics,绘制表格?

标签 c# asp.net drawrectangle system.drawing.graphics

有没有人有使用此 System.Drawing.Graphics 库使用 DrawRectangle 或 DrawRectangles 或任何其他方法绘制表格的示例?

我尝试使用 DrawRectangle 进行设置,但这很困难,做一些简单的事情需要很长时间,而且它不是一个直观的工具。 我在网络上撰写了一些文章,但除了我迄今为止学到的知识之外,我还没有发现任何东西。

最佳答案

解决方案如下:

protected void Page_Load(object sender, EventArgs e) 
{
    var image = new Bitmap(800, 600);
    try 
    {
        var graph = Graphics.FromImage(image);
        graph.FillRectangle(Brushes.White, new Rectangle(new Point(0, 0), image.Size));
        for (int col = 0; col < image.Width; col += 100) {
            graph.DrawLine(Pens.Black, new Point(col, 0), new Point(col, image.Height));
        }
        for (int row = 0; row < image.Height; row += 30) {
            graph.DrawLine(Pens.Black, new Point(0, row), new Point(image.Width, row));
        }
        graph.DrawRectangle(Pens.Black, new Rectangle(0, 0, image.Width - 1, image.Height - 1));

        Response.Clear();
        Response.ContentType = "image/jpeg";
        image.Save(Response.OutputStream, ImageFormat.Jpeg);
        Response.End();
    } 
    finally 
    {
        image.Dispose();
    }
}

关于c# - System.Drawing.Graphics,绘制表格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44937546/

相关文章:

ASP.NET:身份验证过期时如何获取 FormsAuthenticationTicket 对象

c# - 如何从 asp.net 中的自定义 FileUpload 获取文件流?

.net - ASP.NET 中文本框的自动完成搜索组件

c# - 更新 DataGridCell 的绑定(bind)值时创建动画

c# - 进程无法访问文件异常

c# - 在字典中键的值列表中插入值

Android 绘制自定义形状

c++ - 如何将矩形附加到 QGraphicsView

c# - 如何在运行时修改 PropertyGrid(添加/删除属性和动态类型/枚举)