【问题标题】:Datagridview to draw wafer mapDatagridview绘制晶圆图
【发布时间】:2013-08-13 07:07:31
【问题描述】:

目前我正在使用 C# datagridview 绘制包含 >500 行和 >700 列的晶圆图。

但是,有几个问题:

  1. 性能缓慢。由于我需要调整列宽,我必须循环并单独分配。

    for (int i = 0; i < this.dgvCompleteMapGrid.Columns.Count; i++)
    {
      this.dgvCompleteMapGrid.Columns[i].Width = 8;
    }
    
  2. 我只需要为具有值的单元格绘制单元格边界,因为晶圆图几乎是圆形的。我正在使用 cellpainting 事件:

     if (e.Value != null) {
            if (e.Value.ToString() == "")
            {
             e.AdvancedBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None;                    
            }
            else
            {                    
                if (e.Value.ToString() == "1")
                {
                    e.CellStyle.BackColor = Color.Lime;
                }
                else
                {
                    e.CellStyle.BackColor = Color.Red;
                }
    
                //check if the top border set None for neighbor empty value cell
                if (e.AdvancedBorderStyle.Top.ToString() == "None")
                {
    
           e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.Single;
                }   
                //repeat the same for left right and bottom
            }
        }
    

但是,它似乎会为大多数单元格绘制多个边框副本。

是否推荐使用 Datagridview?我尝试在面板上绘制矩形,性能更差。

【问题讨论】:

  • 我认为您应该在DoubleBuffered Panel 上绘制所有内容并计算所有视图中的点以进行绘制。 700 columns 对于 DataGridView 有点多,即使你什么都不做(自定义绘制),可能会出现一点闪烁。
  • 您的绘图是要进行动画处理还是只是一次性数据可视化?如果只是一次,则在位图上绘制所有内容,然后将其显示在面板中作为背景。如果它是动画的,你将不得不按照 King King 所说的去做。是的,DataGridView 在这里不是正确的选择。
  • 感谢您的回复。是的,我已经在使用 DoubleBuffered Panel。要在 DGV 中绘制 >500 列,最小列宽为 1 像素。是否可以绘制小于 1 像素的单元格?我想在没有滚动条的 1 个屏幕中放入 >500 列。
  • @Tombala 如果 DGV 不是正确的选择,您能建议我应该尝试什么吗?
  • 我最近使用 PictureBox (PB) 为我的画布编写了一个 Wire World 模拟器。我在幕后绘制位图。当 bmp 准备好后,我设置 PB.Image = bitmap。我得到大约 5 FPS 必须完全重新生成整个位图,因此绘制需要少量时间。我确实创建了一个从 PB 派生的新 PB 类,覆盖 OnPaint,并在调用 base.OnPaint 之前设置 SmoothingMode、Interpollat​​ionMode、CompositingMode 和 CompositingQuality 以提高速度。

标签: c# .net winforms datagridview


【解决方案1】:

这是我的图片框,它允许像素化调整大小(相对于插值)。例如。类似于放大 Microsoft Paint 图片。

using System.Windows.Forms;

namespace WireWorld
{
    public class ZoomablePicturebox : PictureBox
    {
        public ZoomablePicturebox()
        {
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            pe.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
            pe.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            pe.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
            pe.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
            base.OnPaint(pe);
        }
    }
}

为了生成位图,我使用这样的东西:

// Pick width and height for your case
Bitmap MyBitmap = new Bitmap(width, height);
using (var g = Graphics.FromImage(retVal))
    g.Clear(BackColor); // Pick a background fill color
// Draw your points, whatever your loop needs to be and your point definition is
foreach (MyPointDef point in _Points)
{
    MyBitmap.SetPixel(point.X, point.Y, point.Color);
}

然后我在表单的面板中放置了一个图片框。然后面板提供滚动。我可以设置图片和缩放如下:

canvasPB.SizeMode = PictureBoxSizeMode.Zoom; // Ensures picture is resized as we resize picturebox
canvasPB.Image = MyBitmap;
canvasPB.Height = canvasPB.Image.Height * Zoom; // Zoom is 1, 2, 3, etc, for 1X, 2X, ...
canvasPB.Width = canvasPB.Image.Width * Zoom;

canvasPB 是我试图用作画布的表单上的图片框的名称。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-26
    • 1970-01-01
    • 2010-09-20
    • 1970-01-01
    • 2021-03-08
    • 2020-04-28
    • 1970-01-01
    • 2010-09-16
    相关资源
    最近更新 更多