// 画单元格,包括背景,文字 和 左上线条 // parameter: // g Graphics对象 // nCol 列号 // 0 字段说明; // 1 字段名; // 2 字段指示符 // 3 字段内容 // rect 区域 如果为null,则自动根据列号计算 但目前不支持 // return: // void internal void DrawCell(Graphics g, int nCol, Rectangle rect) { Debug.Assert(g != null, "g参数不能为null"); string strText = ""; int nWidth = 0; bool bEnabled = this.container.MarcEditor.Enabled; bool bReadOnly = this.container.MarcEditor.ReadOnly; Brush brush = null; try { if (nCol == 0) { // NameCaption Color backColor; if (bEnabled == false || bReadOnly == true) { backColor = SystemColors.Control; } else { backColor = this.container.MarcEditor.defaultNameCaptionBackColor; } // 如果本行为当前活动行,则名称部分高亮显示 if (this.Selected == true)//this.container.marcEditor.CurField == this) { if (backColor.GetBrightness() < 0.5f) { backColor = ControlPaint.Light(backColor); } else { backColor = ControlPaint.Dark(backColor); } } strText = this.m_strNameCaption; nWidth = this.container.record.NameCaptionPureWidth; brush = new SolidBrush(backColor); } else if (nCol == 1) { // Name Color backColor; if (bEnabled == false || bReadOnly == true) { backColor = SystemColors.Control; } else { backColor = this.container.MarcEditor.defaultNameBackColor; } if (this.Name == "###") { backColor = this.container.record.marcEditor.defaultNameCaptionBackColor; } // 如果本行为当前活动行,则名称部分高亮显示 if (this.Selected == true)//this.container.marcEditor.FocusedField == this) { backColor = ControlPaint.Light(backColor); } strText = this.m_strName; nWidth = this.container.record.NamePureWidth; brush = new SolidBrush(backColor); } else if (nCol == 2) { // Indicator Color backColor; if (bEnabled == false || bReadOnly == true) { backColor = SystemColors.Control; } else { backColor = this.container.MarcEditor.defaultIndicatorBackColor; } if (Record.IsControlFieldName(this.Name) == true) { backColor = this.container.MarcEditor.defaultIndicatorBackColorDisabled; } // 如果本行为当前活动行,则名称部分高亮显示 if (this.Selected == true)//this.container.marcEditor.FocusedField == this) { backColor = ControlPaint.Light(backColor); } strText = this.m_strIndicator; nWidth = this.container.record.IndicatorPureWidth; brush = new SolidBrush(backColor); } else if (nCol == 3) { // m_strValue strText = this.m_strValue; nWidth = this.container.record.ValuePureWidth + 0; // 1为微调,正好! if (bEnabled == false || bReadOnly == true) { brush = new SolidBrush(SystemColors.Control); } else { brush = new SolidBrush(this.container.MarcEditor.defaultContentBackColor); } } else { Debug.Assert(false, "nCol的值'" + Convert.ToString(nCol) + "'不合法"); } // new Point(-this.container.MarcEditor.DocumentOrgX + 0, -this.container.MarcEditor.DocumentOrgY + this.container.MarcEditor.DocumentHeight), //new Point(-this.container.MarcEditor.DocumentOrgX + this.container.MarcEditor.DocumentWidth, - this.container.MarcEditor.DocumentOrgY + 0), using (LinearGradientBrush linGrBrush = new LinearGradientBrush( new Point(0, 0), new Point(this.container.MarcEditor.DocumentWidth, 0), Color.FromArgb(255, 240, 240, 240), // 240, 240, 240 Color.FromArgb(255, 255, 255, 255) // Opaque red )) // Opaque blue { linGrBrush.GammaCorrection = true; // --------画背景---------------------------- if ((nCol == 1 || nCol == 2 || nCol == 3) && (bEnabled == true && bReadOnly == false)) { g.FillRectangle(linGrBrush, rect); } else { g.FillRectangle(brush, rect); } } // --------画线条---------------------------- // 只画上,左 // 画上方的线条 Field.DrawLines(g, rect, this.container.record.GridHorzLineHeight, 0, 0, 0, this.container.record.marcEditor.defaultHorzGridColor); // 画左方的线条 int nGridWidth = 0; if (nCol == 1) { nGridWidth = this.container.record.GridVertLineWidthForSplit; } else { nGridWidth = this.container.record.GridVertLineWidth; } // indicator左边的竖线短一点 if (nCol == 2) { rect.Y += 2; rect.Height = this.container.record.NamePureHeight; } Field.DrawLines(g, rect, 0, 0, nGridWidth,//this.container.GridVertLineWidth, 0, this.container.MarcEditor.defaultVertGridColor); if (nCol == 2) // 还原 { rect.Y -= 2; } // --------画文字---------------------------- if (nWidth > 0) { Rectangle textRect = new Rectangle( rect.X + nGridWidth /*this.container.GridVertLineWidth*/ + this.container.record.CellLeftBlank, rect.Y + this.container.record.GridHorzLineHeight + this.container.record.CellTopBlank, nWidth, this.PureHeight); // 这里的 font 是引用,因此不需要释放 Font font = null; if (nCol == 0) { font = this.container.MarcEditor.CaptionFont; //Debug.Assert(font != null, ""); } else if (nCol == 1 || nCol == 2) { font = this.container.MarcEditor.FixedSizeFont; //Debug.Assert(font != null, ""); } else { font = this.container.MarcEditor.Font; // Debug.Assert(font != null, ""); } if (font == null) { font = this.container.MarcEditor.Font; } Debug.Assert(font != null, ""); // System.Drawing.Text.TextRenderingHint oldrenderhint = g.TextRenderingHint; // g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; if (nCol == 0) // 字段名提示 { /* * StringFormat format = StringFormat.GenericDefault; //new StringFormat(); * g.DrawString(strText, * font, * brush, // System.Drawing.Brushes.Blue, * textRect, * format); */ Color textcolor = this.container.MarcEditor.defaultNameCaptionTextColor; if (this.Selected == true) { textcolor = ReverseColor(textcolor); } TextRenderer.DrawText( g, strText, font, textRect, textcolor, TextFormatFlags.EndEllipsis); } else if (nCol == 1) // 字段名 { TextRenderer.DrawText( g, strText, font, textRect, this.container.MarcEditor.defaultNameTextColor, MarcEditor.editflags); // TextFormatFlags.TextBoxControl | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding); } else if (nCol == 2) // 指示符 { TextRenderer.DrawText( g, strText, font, textRect, this.container.MarcEditor.defaultIndicatorTextColor, MarcEditor.editflags); // TextFormatFlags.TextBoxControl | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding); } else { // 内容 #if BIDI_SUPPORT strText = strText.Replace(new string(Record.KERNEL_SUBFLD, 1), "\x200e" + new string(Record.KERNEL_SUBFLD, 1)); #endif TextRenderer.DrawText( g, strText, font, textRect, this.container.MarcEditor.m_contentTextColor, MarcEditor.editflags); // TextFormatFlags.TextBoxControl | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding); } } } finally { if (brush != null) { brush.Dispose(); } } #if NO // 2015/10/19 if (linGrBrush != null) { linGrBrush.Dispose(); } #endif }
// 绘制 internal void Paint(PaintEventArgs pe, int nBaseX, int nBaseY) { if (this.Fields.Count == 0) { return; } int x = nBaseX; int y = nBaseY; // 循环行 for (int i = 0; i < this.Fields.Count; i++) { Field field = this.Fields[i]; // 优化 if (y > pe.ClipRectangle.Y + pe.ClipRectangle.Height) { break; } // 调Field的Paint函数 field.Paint(pe, x, y); y += field.TotalHeight; } // 绘共同的右下的线//////////// Rectangle rect = new Rectangle(nBaseX, nBaseY, this.Width, this.Height); // 调整 if (this.GridVertLineWidth == 1 && this.GridHorzLineHeight == 1) { rect.Height = rect.Height - 1; } // 下 Field.DrawLines(pe.Graphics, rect, 0, this.GridHorzLineHeight, 0, 0, this.marcEditor.defaultHorzGridColor); // 调整 if (this.GridVertLineWidth == 1 && this.GridHorzLineHeight == 1) { rect.Height = rect.Height + 1; } if (this.GridVertLineWidth == 1 || this.GridHorzLineHeight == 1) { rect.Width = rect.Width - 1; } // 右 Field.DrawLines(pe.Graphics, rect, 0, 0, 0, this.GridVertLineWidth, this.marcEditor.defaultVertGridColor); }