protected override Size GetPreferredSize(Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize) { if (base.DataGridView == null) { return(new Size(-1, -1)); } if (cellStyle == null) { throw new ArgumentNullException("cellStyle"); } DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder = new DataGridViewAdvancedBorderStyle(); DataGridViewAdvancedBorderStyle advancedBorderStyle = base.OwningRow.AdjustRowHeaderBorderStyle(base.DataGridView.AdvancedRowHeadersBorderStyle, dataGridViewAdvancedBorderStylePlaceholder, false, false, false, false); Rectangle rectangle = this.BorderWidths(advancedBorderStyle); int borderAndPaddingWidths = (rectangle.Left + rectangle.Width) + cellStyle.Padding.Horizontal; int borderAndPaddingHeights = (rectangle.Top + rectangle.Height) + cellStyle.Padding.Vertical; TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(base.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode); if (base.DataGridView.ApplyVisualStylesToHeaderCells) { Rectangle themeMargins = DataGridViewHeaderCell.GetThemeMargins(graphics); borderAndPaddingWidths += themeMargins.Y; borderAndPaddingWidths += themeMargins.Height; borderAndPaddingHeights += themeMargins.X; borderAndPaddingHeights += themeMargins.Width; } object obj2 = this.GetValue(rowIndex); if (!(obj2 is string)) { obj2 = null; } return(DataGridViewUtilities.GetPreferredRowHeaderSize(graphics, (string)obj2, cellStyle, borderAndPaddingWidths, borderAndPaddingHeights, base.DataGridView.ShowRowErrors, true, constraintSize, flags)); }
protected override Size GetPreferredSize(Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize) { if (DataGridView == null) { return(new Size(-1, -1)); } if (cellStyle == null) { throw new ArgumentNullException(nameof(cellStyle)); } DataGridViewAdvancedBorderStyle dgvabsPlaceholder = new DataGridViewAdvancedBorderStyle(), dgvabsEffective; dgvabsEffective = OwningRow.AdjustRowHeaderBorderStyle(DataGridView.AdvancedRowHeadersBorderStyle, dgvabsPlaceholder, false /*singleVerticalBorderAdded*/, false /*singleHorizontalBorderAdded*/, false /*isFirstDisplayedRow*/, false /*isLastVisibleRow*/); Rectangle borderWidthsRect = BorderWidths(dgvabsEffective); int borderAndPaddingWidths = borderWidthsRect.Left + borderWidthsRect.Width + cellStyle.Padding.Horizontal; int borderAndPaddingHeights = borderWidthsRect.Top + borderWidthsRect.Height + cellStyle.Padding.Vertical; TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode); if (DataGridView.ApplyVisualStylesToHeaderCells) { // Add the theming margins to the borders. Rectangle rectThemeMargins = DataGridViewHeaderCell.GetThemeMargins(graphics); borderAndPaddingWidths += rectThemeMargins.Y; borderAndPaddingWidths += rectThemeMargins.Height; borderAndPaddingHeights += rectThemeMargins.X; borderAndPaddingHeights += rectThemeMargins.Width; } // Intentionally not using GetFormattedValue because header cells don't typically perform formatting. object val = GetValue(rowIndex); if (!(val is string)) { val = null; } return(DataGridViewUtilities.GetPreferredRowHeaderSize(graphics, (string)val, cellStyle, borderAndPaddingWidths, borderAndPaddingHeights, DataGridView.ShowRowErrors, true /*showGlyph*/, constraintSize, flags)); }
private Rectangle PaintPrivate(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, bool computeContentBounds, bool computeErrorIconBounds, bool paint) { Rectangle empty = Rectangle.Empty; if (paint && DataGridViewCell.PaintBorder(paintParts)) { this.PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } Rectangle rect = cellBounds; Rectangle rectangle3 = this.BorderWidths(advancedBorderStyle); rect.Offset(rectangle3.X, rectangle3.Y); rect.Width -= rectangle3.Right; rect.Height -= rectangle3.Bottom; Rectangle destRect = rect; bool flag = (dataGridViewElementState & DataGridViewElementStates.Selected) != DataGridViewElementStates.None; if (base.DataGridView.ApplyVisualStylesToHeaderCells) { if (cellStyle.Padding != Padding.Empty) { if (base.DataGridView.RightToLeftInternal) { rect.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top); } else { rect.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top); } rect.Width -= cellStyle.Padding.Horizontal; rect.Height -= cellStyle.Padding.Vertical; } if ((destRect.Width > 0) && (destRect.Height > 0)) { if (paint && DataGridViewCell.PaintBackground(paintParts)) { int headerState = 1; if ((base.DataGridView.SelectionMode == DataGridViewSelectionMode.FullRowSelect) || (base.DataGridView.SelectionMode == DataGridViewSelectionMode.RowHeaderSelect)) { if (base.ButtonState != ButtonState.Normal) { headerState = 3; } else if ((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == -1)) { headerState = 2; } else if (flag) { headerState = 3; } } using (Bitmap bitmap = new Bitmap(destRect.Height, destRect.Width)) { using (Graphics graphics2 = Graphics.FromImage(bitmap)) { DataGridViewRowHeaderCellRenderer.DrawHeader(graphics2, new Rectangle(0, 0, destRect.Height, destRect.Width), headerState); bitmap.RotateFlip(base.DataGridView.RightToLeftInternal ? RotateFlipType.Rotate90FlipNone : RotateFlipType.Rotate90FlipX); graphics.DrawImage(bitmap, destRect, new Rectangle(0, 0, destRect.Width, destRect.Height), GraphicsUnit.Pixel); } } } Rectangle themeMargins = DataGridViewHeaderCell.GetThemeMargins(graphics); if (base.DataGridView.RightToLeftInternal) { rect.X += themeMargins.Height; } else { rect.X += themeMargins.Y; } rect.Width -= themeMargins.Y + themeMargins.Height; rect.Height -= themeMargins.X + themeMargins.Width; rect.Y += themeMargins.X; } } else { if ((rect.Width > 0) && (rect.Height > 0)) { SolidBrush cachedBrush = base.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && flag) ? cellStyle.SelectionBackColor : cellStyle.BackColor); if ((paint && DataGridViewCell.PaintBackground(paintParts)) && (cachedBrush.Color.A == 0xff)) { graphics.FillRectangle(cachedBrush, rect); } } if (cellStyle.Padding != Padding.Empty) { if (base.DataGridView.RightToLeftInternal) { rect.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top); } else { rect.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top); } rect.Width -= cellStyle.Padding.Horizontal; rect.Height -= cellStyle.Padding.Vertical; } } Bitmap bmp = null; if ((rect.Width > 0) && (rect.Height > 0)) { Rectangle cellValueBounds = rect; string str = formattedValue as string; if (!string.IsNullOrEmpty(str)) { if ((rect.Width >= 0x12) && (rect.Height >= 15)) { if (paint && DataGridViewCell.PaintContentBackground(paintParts)) { if (base.DataGridView.CurrentCellAddress.Y == rowIndex) { if (base.DataGridView.VirtualMode) { if (base.DataGridView.IsCurrentRowDirty && base.DataGridView.ShowEditingIcon) { bmp = GetPencilBitmap(base.DataGridView.RightToLeftInternal); } else if (base.DataGridView.NewRowIndex == rowIndex) { bmp = GetArrowStarBitmap(base.DataGridView.RightToLeftInternal); } else { bmp = GetArrowBitmap(base.DataGridView.RightToLeftInternal); } } else if (base.DataGridView.IsCurrentCellDirty && base.DataGridView.ShowEditingIcon) { bmp = GetPencilBitmap(base.DataGridView.RightToLeftInternal); } else if (base.DataGridView.NewRowIndex == rowIndex) { bmp = GetArrowStarBitmap(base.DataGridView.RightToLeftInternal); } else { bmp = GetArrowBitmap(base.DataGridView.RightToLeftInternal); } } else if (base.DataGridView.NewRowIndex == rowIndex) { bmp = StarBitmap; } if (bmp != null) { Color color; if (base.DataGridView.ApplyVisualStylesToHeaderCells) { color = DataGridViewRowHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor); } else { color = flag ? cellStyle.SelectionForeColor : cellStyle.ForeColor; } lock (bmp) { this.PaintIcon(graphics, bmp, rect, color); } } } if (!base.DataGridView.RightToLeftInternal) { rect.X += 0x12; } rect.Width -= 0x12; } rect.Offset(4, 1); rect.Width -= 9; rect.Height -= 2; if ((rect.Width > 0) && (rect.Height > 0)) { TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(base.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode); if (base.DataGridView.ShowRowErrors && (rect.Width > 0x12)) { Size maxBounds = new Size((rect.Width - 12) - 6, rect.Height); if (DataGridViewCell.TextFitsInBounds(graphics, str, cellStyle.Font, maxBounds, flags)) { if (base.DataGridView.RightToLeftInternal) { rect.X += 0x12; } rect.Width -= 0x12; } } if (DataGridViewCell.PaintContentForeground(paintParts)) { if (paint) { Color color2; if (base.DataGridView.ApplyVisualStylesToHeaderCells) { color2 = DataGridViewRowHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor); } else { color2 = flag ? cellStyle.SelectionForeColor : cellStyle.ForeColor; } if ((flags & TextFormatFlags.SingleLine) != TextFormatFlags.Default) { flags |= TextFormatFlags.EndEllipsis; } TextRenderer.DrawText(graphics, str, cellStyle.Font, rect, color2, flags); } else if (computeContentBounds) { empty = DataGridViewUtilities.GetTextBounds(rect, str, flags, cellStyle); } } } if (cellValueBounds.Width >= 0x21) { if ((paint && base.DataGridView.ShowRowErrors) && DataGridViewCell.PaintErrorIcon(paintParts)) { this.PaintErrorIcon(graphics, clipBounds, cellValueBounds, errorText); return(empty); } if (computeErrorIconBounds && !string.IsNullOrEmpty(errorText)) { empty = base.ComputeErrorIconBounds(cellValueBounds); } } return(empty); } if (((rect.Width >= 0x12) && (rect.Height >= 15)) && (paint && DataGridViewCell.PaintContentBackground(paintParts))) { if (base.DataGridView.CurrentCellAddress.Y == rowIndex) { if (base.DataGridView.VirtualMode) { if (base.DataGridView.IsCurrentRowDirty && base.DataGridView.ShowEditingIcon) { bmp = GetPencilBitmap(base.DataGridView.RightToLeftInternal); } else if (base.DataGridView.NewRowIndex == rowIndex) { bmp = GetArrowStarBitmap(base.DataGridView.RightToLeftInternal); } else { bmp = GetArrowBitmap(base.DataGridView.RightToLeftInternal); } } else if (base.DataGridView.IsCurrentCellDirty && base.DataGridView.ShowEditingIcon) { bmp = GetPencilBitmap(base.DataGridView.RightToLeftInternal); } else if (base.DataGridView.NewRowIndex == rowIndex) { bmp = GetArrowStarBitmap(base.DataGridView.RightToLeftInternal); } else { bmp = GetArrowBitmap(base.DataGridView.RightToLeftInternal); } } else if (base.DataGridView.NewRowIndex == rowIndex) { bmp = StarBitmap; } if (bmp != null) { lock (bmp) { Color color3; if (base.DataGridView.ApplyVisualStylesToHeaderCells) { color3 = DataGridViewRowHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor); } else { color3 = flag ? cellStyle.SelectionForeColor : cellStyle.ForeColor; } this.PaintIcon(graphics, bmp, rect, color3); } } } if (cellValueBounds.Width >= 0x21) { if ((paint && base.DataGridView.ShowRowErrors) && DataGridViewCell.PaintErrorIcon(paintParts)) { base.PaintErrorIcon(graphics, cellStyle, rowIndex, cellBounds, cellValueBounds, errorText); return(empty); } if (computeErrorIconBounds && !string.IsNullOrEmpty(errorText)) { empty = base.ComputeErrorIconBounds(cellValueBounds); } } } return(empty); }
private Rectangle PaintPrivate(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object formattedValue, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, bool paint) { Rectangle empty = Rectangle.Empty; if (paint && DataGridViewCell.PaintBorder(paintParts)) { this.PaintBorder(g, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } Rectangle bounds = cellBounds; Rectangle rectangle3 = this.BorderWidths(advancedBorderStyle); bounds.Offset(rectangle3.X, rectangle3.Y); bounds.Width -= rectangle3.Right; bounds.Height -= rectangle3.Bottom; Rectangle destRect = bounds; bool flag = (dataGridViewElementState & DataGridViewElementStates.Selected) != DataGridViewElementStates.None; if (base.DataGridView.ApplyVisualStylesToHeaderCells) { if ((cellStyle.Padding != Padding.Empty) && (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; } if ((paint && DataGridViewCell.PaintBackground(paintParts)) && ((destRect.Width > 0) && (destRect.Height > 0))) { int headerState = 1; if (((base.OwningColumn != null) && (base.OwningColumn.SortMode != DataGridViewColumnSortMode.NotSortable)) || ((base.DataGridView.SelectionMode == DataGridViewSelectionMode.FullColumnSelect) || (base.DataGridView.SelectionMode == DataGridViewSelectionMode.ColumnHeaderSelect))) { if (base.ButtonState != ButtonState.Normal) { headerState = 3; } else if ((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == base.ColumnIndex)) { headerState = 2; } else if (flag) { headerState = 3; } } if (base.DataGridView.RightToLeftInternal) { Bitmap flipXPThemesBitmap = base.FlipXPThemesBitmap; if (((flipXPThemesBitmap == null) || (flipXPThemesBitmap.Width < destRect.Width)) || (((flipXPThemesBitmap.Width > (2 * destRect.Width)) || (flipXPThemesBitmap.Height < destRect.Height)) || (flipXPThemesBitmap.Height > (2 * destRect.Height)))) { flipXPThemesBitmap = base.FlipXPThemesBitmap = new Bitmap(destRect.Width, destRect.Height); } DataGridViewColumnHeaderCellRenderer.DrawHeader(Graphics.FromImage(flipXPThemesBitmap), new Rectangle(0, 0, destRect.Width, destRect.Height), headerState); flipXPThemesBitmap.RotateFlip(RotateFlipType.RotateNoneFlipX); g.DrawImage(flipXPThemesBitmap, destRect, new Rectangle(flipXPThemesBitmap.Width - destRect.Width, 0, destRect.Width, destRect.Height), GraphicsUnit.Pixel); } else { DataGridViewColumnHeaderCellRenderer.DrawHeader(g, destRect, headerState); } } Rectangle themeMargins = DataGridViewHeaderCell.GetThemeMargins(g); bounds.Y += themeMargins.Y; bounds.Height -= themeMargins.Y + themeMargins.Height; if (base.DataGridView.RightToLeftInternal) { bounds.X += themeMargins.Width; bounds.Width -= themeMargins.X + themeMargins.Width; } else { bounds.X += themeMargins.X; bounds.Width -= themeMargins.X + themeMargins.Width; } } else { if ((paint && DataGridViewCell.PaintBackground(paintParts)) && ((destRect.Width > 0) && (destRect.Height > 0))) { SolidBrush cachedBrush = base.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && flag) ? cellStyle.SelectionBackColor : cellStyle.BackColor); if (cachedBrush.Color.A == 0xff) { g.FillRectangle(cachedBrush, destRect); } } 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; } } bool flag2 = false; Point point = new Point(0, 0); string str = formattedValue as string; bounds.Y++; bounds.Height -= 2; if (((((bounds.Width - 2) - 2) > 0) && (bounds.Height > 0)) && !string.IsNullOrEmpty(str)) { Color color; bounds.Offset(2, 0); bounds.Width -= 4; if (base.DataGridView.ApplyVisualStylesToHeaderCells) { color = DataGridViewColumnHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor); } else { color = flag ? cellStyle.SelectionForeColor : cellStyle.ForeColor; } if ((base.OwningColumn != null) && (base.OwningColumn.SortMode != DataGridViewColumnSortMode.NotSortable)) { bool flag3; int maxWidth = ((bounds.Width - 2) - 9) - 8; if (((maxWidth > 0) && (DataGridViewCell.GetPreferredTextHeight(g, base.DataGridView.RightToLeftInternal, str, cellStyle, maxWidth, out flag3) <= bounds.Height)) && !flag3) { flag2 = this.SortGlyphDirection != SortOrder.None; bounds.Width -= 0x13; if (base.DataGridView.RightToLeftInternal) { bounds.X += 0x13; point = new Point((((bounds.Left - 2) - 2) - 4) - 9, bounds.Top + ((bounds.Height - 7) / 2)); } else { point = new Point(((bounds.Right + 2) + 2) + 4, bounds.Top + ((bounds.Height - 7) / 2)); } } } 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(g, str, cellStyle.Font, bounds, color, flags); } } else { empty = DataGridViewUtilities.GetTextBounds(bounds, str, flags, cellStyle); } } else if ((paint && (this.SortGlyphDirection != SortOrder.None)) && ((bounds.Width >= 0x11) && (bounds.Height >= 7))) { flag2 = true; point = new Point(bounds.Left + ((bounds.Width - 9) / 2), bounds.Top + ((bounds.Height - 7) / 2)); } if ((paint && flag2) && DataGridViewCell.PaintContentBackground(paintParts)) { Pen darkPen = null; Pen lightPen = null; base.GetContrastedPens(cellStyle.BackColor, ref darkPen, ref lightPen); if (this.SortGlyphDirection != SortOrder.Ascending) { switch (advancedBorderStyle.Right) { case DataGridViewAdvancedCellBorderStyle.Inset: g.DrawLine(lightPen, point.X, point.Y + 1, (point.X + 4) - 1, (point.Y + 7) - 1); g.DrawLine(lightPen, (int)(point.X + 1), (int)(point.Y + 1), (int)((point.X + 4) - 1), (int)((point.Y + 7) - 1)); g.DrawLine(darkPen, (int)(point.X + 4), (int)((point.Y + 7) - 1), (int)((point.X + 9) - 2), (int)(point.Y + 1)); g.DrawLine(darkPen, (int)(point.X + 4), (int)((point.Y + 7) - 1), (int)((point.X + 9) - 3), (int)(point.Y + 1)); g.DrawLine(darkPen, point.X, point.Y, (point.X + 9) - 2, point.Y); return(empty); case DataGridViewAdvancedCellBorderStyle.Outset: case DataGridViewAdvancedCellBorderStyle.OutsetDouble: case DataGridViewAdvancedCellBorderStyle.OutsetPartial: g.DrawLine(darkPen, point.X, point.Y + 1, (point.X + 4) - 1, (point.Y + 7) - 1); g.DrawLine(darkPen, (int)(point.X + 1), (int)(point.Y + 1), (int)((point.X + 4) - 1), (int)((point.Y + 7) - 1)); g.DrawLine(lightPen, (int)(point.X + 4), (int)((point.Y + 7) - 1), (int)((point.X + 9) - 2), (int)(point.Y + 1)); g.DrawLine(lightPen, (int)(point.X + 4), (int)((point.Y + 7) - 1), (int)((point.X + 9) - 3), (int)(point.Y + 1)); g.DrawLine(lightPen, point.X, point.Y, (point.X + 9) - 2, point.Y); return(empty); } for (int j = 0; j < 4; j++) { g.DrawLine(darkPen, (int)(point.X + j), (int)((point.Y + j) + 2), (int)(((point.X + 9) - j) - 1), (int)((point.Y + j) + 2)); } g.DrawLine(darkPen, (int)(point.X + 4), (int)((point.Y + 4) + 1), (int)(point.X + 4), (int)((point.Y + 4) + 2)); return(empty); } switch (advancedBorderStyle.Right) { case DataGridViewAdvancedCellBorderStyle.Inset: g.DrawLine(lightPen, point.X, (point.Y + 7) - 2, (point.X + 4) - 1, point.Y); g.DrawLine(lightPen, point.X + 1, (point.Y + 7) - 2, (point.X + 4) - 1, point.Y); g.DrawLine(darkPen, point.X + 4, point.Y, (point.X + 9) - 2, (point.Y + 7) - 2); g.DrawLine(darkPen, point.X + 4, point.Y, (point.X + 9) - 3, (point.Y + 7) - 2); g.DrawLine(darkPen, point.X, (point.Y + 7) - 1, (point.X + 9) - 2, (point.Y + 7) - 1); return(empty); case DataGridViewAdvancedCellBorderStyle.Outset: case DataGridViewAdvancedCellBorderStyle.OutsetDouble: case DataGridViewAdvancedCellBorderStyle.OutsetPartial: g.DrawLine(darkPen, point.X, (point.Y + 7) - 2, (point.X + 4) - 1, point.Y); g.DrawLine(darkPen, point.X + 1, (point.Y + 7) - 2, (point.X + 4) - 1, point.Y); g.DrawLine(lightPen, point.X + 4, point.Y, (point.X + 9) - 2, (point.Y + 7) - 2); g.DrawLine(lightPen, point.X + 4, point.Y, (point.X + 9) - 3, (point.Y + 7) - 2); g.DrawLine(lightPen, point.X, (point.Y + 7) - 1, (point.X + 9) - 2, (point.Y + 7) - 1); return(empty); } for (int i = 0; i < 4; i++) { g.DrawLine(darkPen, (int)(point.X + i), (int)(((point.Y + 7) - i) - 1), (int)(((point.X + 9) - i) - 1), (int)(((point.Y + 7) - i) - 1)); } g.DrawLine(darkPen, (int)(point.X + 4), (int)(((point.Y + 7) - 4) - 1), (int)(point.X + 4), (int)((point.Y + 7) - 4)); } return(empty); }
protected override Size GetPreferredSize(Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize) { Size size; if (rowIndex != -1) { throw new ArgumentOutOfRangeException("rowIndex"); } if (base.DataGridView == null) { return(new Size(-1, -1)); } if (cellStyle == null) { throw new ArgumentNullException("cellStyle"); } DataGridViewFreeDimension freeDimensionFromConstraint = DataGridViewCell.GetFreeDimensionFromConstraint(constraintSize); DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder = new DataGridViewAdvancedBorderStyle(); DataGridViewAdvancedBorderStyle advancedBorderStyle = base.DataGridView.AdjustColumnHeaderBorderStyle(base.DataGridView.AdvancedColumnHeadersBorderStyle, dataGridViewAdvancedBorderStylePlaceholder, false, false); Rectangle rectangle = this.BorderWidths(advancedBorderStyle); int num = (rectangle.Left + rectangle.Width) + cellStyle.Padding.Horizontal; int num2 = (rectangle.Top + rectangle.Height) + cellStyle.Padding.Vertical; TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(base.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode); string str = this.GetValue(rowIndex) as string; switch (freeDimensionFromConstraint) { case DataGridViewFreeDimension.Height: { Size empty; int num3 = constraintSize.Width - num; size = new Size(0, 0); if (((num3 < 0x11) || (base.OwningColumn == null)) || (base.OwningColumn.SortMode == DataGridViewColumnSortMode.NotSortable)) { empty = Size.Empty; } else { empty = new Size(0x11, 7); } if ((((num3 - 2) - 2) > 0) && !string.IsNullOrEmpty(str)) { if (cellStyle.WrapMode == DataGridViewTriState.True) { if ((empty.Width > 0) && (((((num3 - 2) - 2) - 2) - empty.Width) > 0)) { size = new Size(0, DataGridViewCell.MeasureTextHeight(graphics, str, cellStyle.Font, (((num3 - 2) - 2) - 2) - empty.Width, flags)); } else { size = new Size(0, DataGridViewCell.MeasureTextHeight(graphics, str, cellStyle.Font, (num3 - 2) - 2, flags)); } } else { size = new Size(0, DataGridViewCell.MeasureTextSize(graphics, str, cellStyle.Font, flags).Height); } } size.Height = Math.Max(size.Height, empty.Height); size.Height = Math.Max(size.Height, 1); goto Label_0391; } case DataGridViewFreeDimension.Width: size = new Size(0, 0); if (!string.IsNullOrEmpty(str)) { if (cellStyle.WrapMode != DataGridViewTriState.True) { size = new Size(DataGridViewCell.MeasureTextSize(graphics, str, cellStyle.Font, flags).Width, 0); break; } size = new Size(DataGridViewCell.MeasureTextWidth(graphics, str, cellStyle.Font, Math.Max(1, (constraintSize.Height - num2) - 2), flags), 0); } break; default: if (!string.IsNullOrEmpty(str)) { if (cellStyle.WrapMode == DataGridViewTriState.True) { size = DataGridViewCell.MeasureTextPreferredSize(graphics, str, cellStyle.Font, 5f, flags); } else { size = DataGridViewCell.MeasureTextSize(graphics, str, cellStyle.Font, flags); } } else { size = new Size(0, 0); } if ((base.OwningColumn != null) && (base.OwningColumn.SortMode != DataGridViewColumnSortMode.NotSortable)) { size.Width += 0x11; if (!string.IsNullOrEmpty(str)) { size.Width += 2; } size.Height = Math.Max(size.Height, 7); } size.Width = Math.Max(size.Width, 1); size.Height = Math.Max(size.Height, 1); goto Label_0391; } if (((((constraintSize.Height - num2) - 2) > 7) && (base.OwningColumn != null)) && (base.OwningColumn.SortMode != DataGridViewColumnSortMode.NotSortable)) { size.Width += 0x11; if (!string.IsNullOrEmpty(str)) { size.Width += 2; } } size.Width = Math.Max(size.Width, 1); Label_0391: if (freeDimensionFromConstraint != DataGridViewFreeDimension.Height) { if (!string.IsNullOrEmpty(str)) { size.Width += 4; } size.Width += num; } if (freeDimensionFromConstraint != DataGridViewFreeDimension.Width) { size.Height += 2 + num2; } if (base.DataGridView.ApplyVisualStylesToHeaderCells) { Rectangle themeMargins = DataGridViewHeaderCell.GetThemeMargins(graphics); if (freeDimensionFromConstraint != DataGridViewFreeDimension.Height) { size.Width += themeMargins.X + themeMargins.Width; } if (freeDimensionFromConstraint != DataGridViewFreeDimension.Width) { size.Height += themeMargins.Y + themeMargins.Height; } } return(size); }
private Rectangle PaintPrivate(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, 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 != 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; if (paint && DataGridViewCell.PaintBorder(paintParts)) { PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } Rectangle valBounds = cellBounds; Rectangle borderWidths = BorderWidths(advancedBorderStyle); valBounds.Offset(borderWidths.X, borderWidths.Y); valBounds.Width -= borderWidths.Right; valBounds.Height -= borderWidths.Bottom; Rectangle backgroundBounds = valBounds; bool cellSelected = (dataGridViewElementState & DataGridViewElementStates.Selected) != 0; if (DataGridView.ApplyVisualStylesToHeaderCells) { 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; } if (backgroundBounds.Width > 0 && backgroundBounds.Height > 0) { if (paint && DataGridViewCell.PaintBackground(paintParts)) { // Theming int state = (int)HeaderItemState.Normal; if (DataGridView.SelectionMode == DataGridViewSelectionMode.FullRowSelect || DataGridView.SelectionMode == DataGridViewSelectionMode.RowHeaderSelect) { if (ButtonState != ButtonState.Normal) { Debug.Assert(ButtonState == ButtonState.Pushed); state = (int)HeaderItemState.Pressed; } else if (DataGridView.MouseEnteredCellAddress.Y == rowIndex && DataGridView.MouseEnteredCellAddress.X == -1) { state = (int)HeaderItemState.Hot; } else if (cellSelected) { state = (int)HeaderItemState.Pressed; } } // Flip the column header background using (Bitmap bmFlipXPThemes = new Bitmap(backgroundBounds.Height, backgroundBounds.Width)) { using (Graphics gFlip = Graphics.FromImage(bmFlipXPThemes)) { DataGridViewRowHeaderCellRenderer.DrawHeader(gFlip, new Rectangle(0, 0, backgroundBounds.Height, backgroundBounds.Width), state); bmFlipXPThemes.RotateFlip(DataGridView.RightToLeftInternal ? RotateFlipType.Rotate90FlipNone : RotateFlipType.Rotate270FlipY); graphics.DrawImage(bmFlipXPThemes, backgroundBounds, new Rectangle(0, 0, backgroundBounds.Width, backgroundBounds.Height), GraphicsUnit.Pixel); } } } // update the val bounds Rectangle rectThemeMargins = DataGridViewHeaderCell.GetThemeMargins(graphics); if (DataGridView.RightToLeftInternal) { valBounds.X += rectThemeMargins.Height; } else { valBounds.X += rectThemeMargins.Y; } valBounds.Width -= rectThemeMargins.Y + rectThemeMargins.Height; valBounds.Height -= rectThemeMargins.X + rectThemeMargins.Width; valBounds.Y += rectThemeMargins.X; } } else { // No visual style applied if (valBounds.Width > 0 && valBounds.Height > 0) { SolidBrush br = DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && cellSelected) ? cellStyle.SelectionBackColor : cellStyle.BackColor); if (paint && DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255) { graphics.FillRectangle(br, valBounds); } } 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; } } Bitmap bmp = null; if (valBounds.Width > 0 && valBounds.Height > 0) { Rectangle errorBounds = valBounds; string formattedString = formattedValue as string; if (!string.IsNullOrEmpty(formattedString)) { // There is text to display if (valBounds.Width >= s_iconsWidth + 2 * RowHeaderIconMarginWidth && valBounds.Height >= s_iconsHeight + 2 * RowHeaderIconMarginHeight) { if (paint && DataGridViewCell.PaintContentBackground(paintParts)) { // There is enough room for the potential glyph which is the first priority if (DataGridView.CurrentCellAddress.Y == rowIndex) { if (DataGridView.VirtualMode) { if (DataGridView.IsCurrentRowDirty && DataGridView.ShowEditingIcon) { bmp = GetPencilBitmap(DataGridView.RightToLeftInternal); } else if (DataGridView.NewRowIndex == rowIndex) { bmp = GetArrowStarBitmap(DataGridView.RightToLeftInternal); } else { bmp = GetArrowBitmap(DataGridView.RightToLeftInternal); } } else { if (DataGridView.IsCurrentCellDirty && DataGridView.ShowEditingIcon) { bmp = GetPencilBitmap(DataGridView.RightToLeftInternal); } else if (DataGridView.NewRowIndex == rowIndex) { bmp = GetArrowStarBitmap(DataGridView.RightToLeftInternal); } else { bmp = GetArrowBitmap(DataGridView.RightToLeftInternal); } } } else if (DataGridView.NewRowIndex == rowIndex) { bmp = DataGridViewRowHeaderCell.StarBitmap; } if (bmp != null) { Color iconColor; if (DataGridView.ApplyVisualStylesToHeaderCells) { iconColor = DataGridViewRowHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor); } else { iconColor = cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor; } lock (bmp) { PaintIcon(graphics, bmp, valBounds, iconColor); } } } if (!DataGridView.RightToLeftInternal) { valBounds.X += s_iconsWidth + 2 * RowHeaderIconMarginWidth; } valBounds.Width -= s_iconsWidth + 2 * RowHeaderIconMarginWidth; Debug.Assert(valBounds.Width >= 0); Debug.Assert(valBounds.Height >= 0); } // Second priority is text // Font independent margins valBounds.Offset(HorizontalTextMarginLeft + ContentMarginWidth, VerticalTextMargin); valBounds.Width -= HorizontalTextMarginLeft + 2 * ContentMarginWidth + HorizontalTextMarginRight; valBounds.Height -= 2 * VerticalTextMargin; if (valBounds.Width > 0 && valBounds.Height > 0) { TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode); if (DataGridView.ShowRowErrors && valBounds.Width > s_iconsWidth + 2 * RowHeaderIconMarginWidth) { // Check if the text fits if we remove the room required for the row error icon Size maxBounds = new Size(valBounds.Width - s_iconsWidth - 2 * RowHeaderIconMarginWidth, valBounds.Height); if (DataGridViewCell.TextFitsInBounds(graphics, formattedString, cellStyle.Font, maxBounds, flags)) { // There is enough room for both the text and the row error icon, so use it all. if (DataGridView.RightToLeftInternal) { valBounds.X += s_iconsWidth + 2 * RowHeaderIconMarginWidth; } valBounds.Width -= s_iconsWidth + 2 * RowHeaderIconMarginWidth; } } if (DataGridViewCell.PaintContentForeground(paintParts)) { if (paint) { Color textColor; if (DataGridView.ApplyVisualStylesToHeaderCells) { textColor = DataGridViewRowHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor); } else { textColor = cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor; } if ((flags & TextFormatFlags.SingleLine) != 0) { flags |= TextFormatFlags.EndEllipsis; } TextRenderer.DrawText(graphics, formattedString, cellStyle.Font, valBounds, textColor, flags); } else if (computeContentBounds) { resultBounds = DataGridViewUtilities.GetTextBounds(valBounds, formattedString, flags, cellStyle); } } } // Third priority is the row error icon, which may be painted on top of text if (errorBounds.Width >= 3 * RowHeaderIconMarginWidth + 2 * s_iconsWidth) { // There is enough horizontal room for the error icon and the glyph if (paint && DataGridView.ShowRowErrors && DataGridViewCell.PaintErrorIcon(paintParts)) { PaintErrorIcon(graphics, clipBounds, errorBounds, errorText); } else if (computeErrorIconBounds) { if (!string.IsNullOrEmpty(errorText)) { resultBounds = ComputeErrorIconBounds(errorBounds); } } } } else { // There is no text to display if (valBounds.Width >= s_iconsWidth + 2 * RowHeaderIconMarginWidth && valBounds.Height >= s_iconsHeight + 2 * RowHeaderIconMarginHeight) { if (paint && DataGridViewCell.PaintContentBackground(paintParts)) { // There is enough room for the potential icon if (DataGridView.CurrentCellAddress.Y == rowIndex) { if (DataGridView.VirtualMode) { if (DataGridView.IsCurrentRowDirty && DataGridView.ShowEditingIcon) { bmp = GetPencilBitmap(DataGridView.RightToLeftInternal); } else if (DataGridView.NewRowIndex == rowIndex) { bmp = GetArrowStarBitmap(DataGridView.RightToLeftInternal); } else { bmp = GetArrowBitmap(DataGridView.RightToLeftInternal); } } else { if (DataGridView.IsCurrentCellDirty && DataGridView.ShowEditingIcon) { bmp = GetPencilBitmap(DataGridView.RightToLeftInternal); } else if (DataGridView.NewRowIndex == rowIndex) { bmp = GetArrowStarBitmap(DataGridView.RightToLeftInternal); } else { bmp = GetArrowBitmap(DataGridView.RightToLeftInternal); } } } else if (DataGridView.NewRowIndex == rowIndex) { bmp = DataGridViewRowHeaderCell.StarBitmap; } if (bmp != null) { lock (bmp) { Color iconColor; if (DataGridView.ApplyVisualStylesToHeaderCells) { iconColor = DataGridViewRowHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor); } else { iconColor = cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor; } PaintIcon(graphics, bmp, valBounds, iconColor); } } } } if (errorBounds.Width >= 3 * RowHeaderIconMarginWidth + 2 * s_iconsWidth) { // There is enough horizontal room for the error icon if (paint && DataGridView.ShowRowErrors && DataGridViewCell.PaintErrorIcon(paintParts)) { PaintErrorIcon(graphics, cellStyle, rowIndex, cellBounds, errorBounds, errorText); } else if (computeErrorIconBounds) { if (!string.IsNullOrEmpty(errorText)) { resultBounds = ComputeErrorIconBounds(errorBounds); } } } } } // else no room for content or error icon, resultBounds = Rectangle.Empty return(resultBounds); }