Datagridview绘制晶圆图

目前我正在使用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? 我试图在面板上绘制矩形,性能更差。

这是我的Picturebox,允许像素化resize(与插值相比)。 例如,类似于放大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是我的表单上的Picturebox的名称,我试图用作我的canvas。