private Rectangle PaintPrivate(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, bool computeContentBounds, bool computeErrorIconBounds, bool paint) { // Parameter checking. // One bit and one bit only should be turned on Debug.Assert(paint || computeContentBounds || computeErrorIconBounds); Debug.Assert(!paint || !computeContentBounds || !computeErrorIconBounds); Debug.Assert(!computeContentBounds || !computeErrorIconBounds || !paint); Debug.Assert(!computeErrorIconBounds || !paint || !computeContentBounds); Debug.Assert(cellStyle is not null); // If computeContentBounds == TRUE then resultBounds will be the contentBounds. // If computeErrorIconBounds == TRUE then resultBounds will be the error icon bounds. // Else resultBounds will be Rectangle.Empty; Rectangle resultBounds = Rectangle.Empty; Rectangle valBounds = cellBounds; Rectangle borderWidths = BorderWidths(advancedBorderStyle); valBounds.Offset(borderWidths.X, borderWidths.Y); valBounds.Width -= borderWidths.Right; valBounds.Height -= borderWidths.Bottom; bool cellSelected = (cellState & DataGridViewElementStates.Selected) != 0; if (paint && PaintBackground(paintParts)) { if (DataGridView.ApplyVisualStylesToHeaderCells) { // Theming int state = (int)HeaderItemState.Normal; if (ButtonState != ButtonState.Normal) { Debug.Assert(ButtonState == ButtonState.Pushed); state = (int)HeaderItemState.Pressed; } else if (DataGridView.MouseEnteredCellAddress.Y == rowIndex && DataGridView.MouseEnteredCellAddress.X == ColumnIndex) { state = (int)HeaderItemState.Hot; } valBounds.Inflate(16, 16); DataGridViewTopLeftHeaderCellRenderer.DrawHeader(graphics, valBounds, state); valBounds.Inflate(-16, -16); } else { Color brushColor = PaintSelectionBackground(paintParts) && cellSelected ? cellStyle.SelectionBackColor : cellStyle.BackColor; if (!brushColor.HasTransparency()) { using var brush = brushColor.GetCachedSolidBrushScope(); graphics.FillRectangle(brush, valBounds); } } } if (paint && PaintBorder(paintParts)) { PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } if (cellStyle.Padding != Padding.Empty) { if (DataGridView.RightToLeftInternal) { valBounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top); } else { valBounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top); } valBounds.Width -= cellStyle.Padding.Horizontal; valBounds.Height -= cellStyle.Padding.Vertical; } Rectangle errorBounds = valBounds; string formattedValueStr = formattedValue as string; // Font independent margins valBounds.Offset(DATAGRIDVIEWTOPLEFTHEADERCELL_horizontalTextMarginLeft, DATAGRIDVIEWTOPLEFTHEADERCELL_verticalTextMargin); valBounds.Width -= DATAGRIDVIEWTOPLEFTHEADERCELL_horizontalTextMarginLeft + DATAGRIDVIEWTOPLEFTHEADERCELL_horizontalTextMarginRight; valBounds.Height -= 2 * DATAGRIDVIEWTOPLEFTHEADERCELL_verticalTextMargin; if (valBounds.Width > 0 && valBounds.Height > 0 && !string.IsNullOrEmpty(formattedValueStr) && (paint || computeContentBounds)) { Color textColor; if (DataGridView.ApplyVisualStylesToHeaderCells) { textColor = DataGridViewTopLeftHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor); } else { textColor = cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor; } TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode); if (paint) { if (PaintContentForeground(paintParts)) { if ((flags & TextFormatFlags.SingleLine) != 0) { flags |= TextFormatFlags.EndEllipsis; } TextRenderer.DrawText(graphics, formattedValueStr, cellStyle.Font, valBounds, textColor, flags); } } else { Debug.Assert(computeContentBounds); resultBounds = DataGridViewUtilities.GetTextBounds(valBounds, formattedValueStr, flags, cellStyle); } } else if (computeErrorIconBounds && !string.IsNullOrEmpty(errorText)) { resultBounds = ComputeErrorIconBounds(errorBounds); } if (DataGridView.ShowCellErrors && paint && PaintErrorIcon(paintParts)) { PaintErrorIcon(graphics, cellStyle, rowIndex, cellBounds, errorBounds, errorText); } return(resultBounds); }
private Rectangle PaintPrivate(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, bool computeContentBounds, bool computeErrorIconBounds, bool paint) { Rectangle empty = Rectangle.Empty; Rectangle bounds = cellBounds; Rectangle rectangle3 = this.BorderWidths(advancedBorderStyle); bounds.Offset(rectangle3.X, rectangle3.Y); bounds.Width -= rectangle3.Right; bounds.Height -= rectangle3.Bottom; bool flag = (cellState & DataGridViewElementStates.Selected) != DataGridViewElementStates.None; if (paint && DataGridViewCell.PaintBackground(paintParts)) { if (base.DataGridView.ApplyVisualStylesToHeaderCells) { int headerState = 1; if (base.ButtonState != ButtonState.Normal) { headerState = 3; } else if ((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == base.ColumnIndex)) { headerState = 2; } bounds.Inflate(0x10, 0x10); DataGridViewTopLeftHeaderCellRenderer.DrawHeader(graphics, bounds, headerState); bounds.Inflate(-16, -16); } else { SolidBrush cachedBrush = base.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && flag) ? cellStyle.SelectionBackColor : cellStyle.BackColor); if (cachedBrush.Color.A == 0xff) { graphics.FillRectangle(cachedBrush, bounds); } } } if (paint && DataGridViewCell.PaintBorder(paintParts)) { this.PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } if (cellStyle.Padding != Padding.Empty) { if (base.DataGridView.RightToLeftInternal) { bounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top); } else { bounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top); } bounds.Width -= cellStyle.Padding.Horizontal; bounds.Height -= cellStyle.Padding.Vertical; } Rectangle cellValueBounds = bounds; string str = formattedValue as string; bounds.Offset(1, 1); bounds.Width -= 3; bounds.Height -= 2; if ((((bounds.Width > 0) && (bounds.Height > 0)) && !string.IsNullOrEmpty(str)) && (paint || computeContentBounds)) { Color color; if (base.DataGridView.ApplyVisualStylesToHeaderCells) { color = DataGridViewTopLeftHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor); } else { color = flag ? cellStyle.SelectionForeColor : cellStyle.ForeColor; } TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(base.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode); if (paint) { if (DataGridViewCell.PaintContentForeground(paintParts)) { if ((flags & TextFormatFlags.SingleLine) != TextFormatFlags.Default) { flags |= TextFormatFlags.EndEllipsis; } TextRenderer.DrawText(graphics, str, cellStyle.Font, bounds, color, flags); } } else { empty = DataGridViewUtilities.GetTextBounds(bounds, str, flags, cellStyle); } } else if (computeErrorIconBounds && !string.IsNullOrEmpty(errorText)) { empty = base.ComputeErrorIconBounds(cellValueBounds); } if ((base.DataGridView.ShowCellErrors && paint) && DataGridViewCell.PaintErrorIcon(paintParts)) { base.PaintErrorIcon(graphics, cellStyle, rowIndex, cellBounds, cellValueBounds, errorText); } return(empty); }