1

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

4

1 回答 1

0

这是我的图片框,它允许像素化调整大小(相对于插值)。例如,类似于放大 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 是我试图用作画布的表单上的图片框的名称。

于 2013-10-29T20:33:38.103 回答