//重绘单元格 private void InvalidateCell(I3ReportCell cell) { if (cell == null) { this.Invalidate(); return; } I3PrintArea area = null; foreach (I3PrintArea tmpArea in reportDatas.PrintAreas.Dic.Values) { if (new List <int>(tmpArea.AllRows).IndexOf(cell.Row) >= 0 && new List <int>(tmpArea.AllCols).IndexOf(cell.Col) >= 0) { area = tmpArea; break; } } if (area == null) { this.Invalidate(); return; } RectangleF contentRect = GetAreaContentRect(area); RectangleF rectF = I3ReportPrintController.CalCellDrawRect_Scale(reportDatas, cell, area, Scale, contentRect, null); Rectangle drawRect = new Rectangle((int)Math.Ceiling(rectF.X), (int)Math.Ceiling(rectF.Y), (int)Math.Ceiling(rectF.Width), (int)Math.Ceiling(rectF.Height)); this.Invalidate(drawRect, false); }
/// <summary> /// 测试单元格 /// </summary> /// <param name="pageIndex"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> private I3ReportCell TestCell(int pageIndex, int x, int y) { if (reportDatas == null || CellItemEventMode == ReportPrint.I3CellItemEventMode.None) { return(null); } I3ReportData reportData = reportDatas.GetReportDataByAreaIndex(pageIndex); int row = TestRow(pageIndex, x, y); int col = TestCol(pageIndex, x, y); if (row < 0 || col < 0) { return(null); } I3ReportCell cell = reportData[row][col]; cell = cell.MergState == I3MergeState.Merged ? reportData.GetMergedStartedCell(row, col) : cell; switch (CellItemEventMode) { case I3CellItemEventMode.CellRect: return(cell); case I3CellItemEventMode.ContentRect: I3PrintArea area = reportDatas.PrintAreas.Dic[pageIndex]; RectangleF fullRect = GetAreaPaperRect(area); RectangleF dataRect = GetAreaContentRect(area); RectangleF rect = I3ReportPrintController.CalCellDrawRect_Scale(reportDatas, cell, area, Scale, dataRect, null); II3CellRenderer renderer = I3CellRendererBuilder.GetRenderer(cell); RectangleF contentRect = renderer.DrawContent(this.CreateGraphics(), Scale, reportData, cell, rect, reportData.GetCellStyle(cell.StyleName), area, false); RectangleF testRect = new RectangleF(x, y, 1, 1); return(contentRect.IntersectsWith(testRect) ? cell : null); default: return(null); } }
/// <summary> /// 绘制 /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { using (Brush brush = new SolidBrush(this.BackColor)) { e.Graphics.FillRectangle(brush, new Rectangle(0, 0, this.Width, this.Height)); } if (this.DesignMode || reportDatas == null) { return; } RectangleF oldClip = e.Graphics.ClipBounds; RectangleF clientRect = new RectangleF(0, 0, this.Width - VScrollWidth, this.Height - HScrollHeight); bool firstPageShowed = false; for (int index = 0; index < reportDatas.PrintAreas.Dic.Count; index++) { #region 纸张区域 I3PrintArea area = reportDatas.PrintAreas.Dic[index]; RectangleF paperRect = GetAreaPaperRect(area); if (!paperRect.IntersectsWith(oldClip) || !paperRect.IntersectsWith(clientRect)) { continue; } if (!firstPageShowed) { firstPageShowed = true; CurPageIndex = index; } #endregion #region 内容区域 RectangleF contentRect = GetAreaContentRect(area); //内容区域不用作剪切区域判断,(非内容区域也需要绘制) #endregion #region 绘制 I3ReportPrintController.PrintAreaToGraphics(e.Graphics, Scale, paperRect, contentRect, reportDatas, area, PaintPageIndex2, index); e.Graphics.SetClip(oldClip); #endregion #region 缩略图页码 if (PaintPageIndex) { string text = string.Format("{0}/{1}", index + 1, reportDatas.PrintAreas.Dic.Count); //缩略图页面还是显示本数据的 //string text = string.Format("{0}/{1}", index + 1 + reportData.PageIndexStart - 1, reportData.TotalPageCount); e.Graphics.SetClip(paperRect); using (Font font = new Font("宋体", 10)) { StringFormat stringFormat = StringFormat.GenericDefault; stringFormat.Alignment = StringAlignment.Near; stringFormat.LineAlignment = StringAlignment.Near; stringFormat.Trimming = StringTrimming.None; stringFormat.FormatFlags = (StringFormatFlags)0; SizeF sizeF = e.Graphics.MeasureString(text, font, 200, stringFormat); RectangleF textRect = new RectangleF(0, 0, sizeF.Width, sizeF.Height); textRect.Y = paperRect.Y + paperRect.Height - 2 - sizeF.Height; textRect.X = paperRect.X + paperRect.Width - 2 - sizeF.Width; e.Graphics.SetClip(textRect); e.Graphics.DrawString(text, font, Brushes.Red, textRect); } } #endregion #region FoucesedCell、MouseOnCell if (HighlightFoucesedCell && this.FoucesedCell != null) { if (new List <int>(area.AllRows).IndexOf(this.FoucesedCell.Row) >= 0 && new List <int>(area.AllCols).IndexOf(this.FoucesedCell.Col) >= 0) { RectangleF rect = I3ReportPrintController.CalCellDrawRect_Scale(reportDatas, this.FoucesedCell, area, Scale, contentRect, null); e.Graphics.SetClip(rect); Pen pen = new Pen(Brushes.Red, 6); e.Graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); } } if (HighlightMouseOnCell && this.MouseOnCell != null) { if (new List <int>(area.AllRows).IndexOf(this.MouseOnCell.Row) >= 0 && new List <int>(area.AllCols).IndexOf(this.MouseOnCell.Col) >= 0) { RectangleF rect = I3ReportPrintController.CalCellDrawRect_Scale(reportDatas, this.MouseOnCell, area, Scale, contentRect, null); e.Graphics.SetClip(rect); Pen pen = new Pen(Brushes.Blue, 6); e.Graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); } } #endregion e.Graphics.SetClip(oldClip); } }