public override void OnDraw(Graphics g) { bool bInDesign = false; if (this.Page != null) { bInDesign = this.Page.InDesignMode; } if (bInDesign) { base.OnDraw(g); int nRows = this.Rows; int nCol = this.Columns; int nWidth = this.Width; int nHeight = this.Height; if (nRows <= 0) { nRows = 1; } if (nCol <= 0) { nCol = 1; } if (nRows == 1 && nCol == 1) { return; } int nGapX = this.GapX; int nGapY = this.GapY; if (nGapX < 0) { nGapX = 0; } if (nGapY < 0) { nGapY = 0; } bool bGetBmp = (_bmp == null); if (!bGetBmp) { if (this.Page != null && !this.Page.ShowingTextInput) { if (this.Page.Left >= 0 && this.Page.Top >= 0) { if (this.Page.AutoScrollPosition.X == 0 && this.Page.AutoScrollPosition.Y == 0) { bGetBmp = true; } } } } if (bGetBmp) { _bmp = WinUtil.CaptureScreenImage(Page.Handle, this.Left, this.Top, this.Width, this.Height, Page.FormBorderStyle != FormBorderStyle.None); } ImageAttributes ia = null; if (_linePen == null) { _linePen = new Pen(new SolidBrush(Color.LightGray)); } ColorMatrix cm = new ColorMatrix(); ia = new ImageAttributes(); cm.Matrix33 = 0.5f; ia.SetColorMatrix(cm); int w = this.Width * nCol; int h = this.Height * nRows; for (int r = 0, dh = this.Top; r <= nRows; r++, dh += this.Height) { g.DrawLine(_linePen, this.Left, dh, this.Left + w, dh); } for (int c = 0, dw = this.Left; c <= nCol; c++, dw += this.Width) { g.DrawLine(_linePen, dw, this.Top, dw, this.Top + h); } if (_bmp != null) { int incH = this.Height + nGapY; int incW = this.Width + nGapX; for (int r = 0, dh = this.Top; r < nRows; r++, dh += incH) { for (int c = 0, dw = this.Left; c < nCol; c++, dw += incW) { if (r != 0 || c != 0) { Rectangle rc = new Rectangle(dw, dh, _bmp.Width, _bmp.Height); if (bInDesign) { g.DrawImage(_bmp, rc, 0, 0, _bmp.Width, _bmp.Height, GraphicsUnit.Pixel, ia); } else { g.DrawImage(_bmp, rc, 0, 0, _bmp.Width, _bmp.Height, GraphicsUnit.Pixel); } } } } } } else { if (_drawItems != null) { for (int r = 0; r < _drawItems.Length; r++) { for (int c = 0; c < _drawItems[r].Length; c++) { _drawItems[r][c].OnDraw(g); } } } } }