internal static void DrawCheckBackground(bool controlEnabled, CheckState controlCheckState, Graphics g, Rectangle bounds, Color checkColor, Color checkBackground, bool disabledColors, ButtonBaseAdapter.ColorData colors) { using (WindowsGraphics graphics = WindowsGraphics.FromGraphics(g)) { WindowsBrush brush; if (!controlEnabled && disabledColors) { brush = new WindowsSolidBrush(graphics.DeviceContext, SystemColors.Control); } else if (((controlCheckState == CheckState.Indeterminate) && (checkBackground == SystemColors.Window)) && disabledColors) { Color color = SystemInformation.HighContrast ? SystemColors.ControlDark : SystemColors.Control; byte red = (byte) ((color.R + SystemColors.Window.R) / 2); byte green = (byte) ((color.G + SystemColors.Window.G) / 2); byte blue = (byte) ((color.B + SystemColors.Window.B) / 2); brush = new WindowsSolidBrush(graphics.DeviceContext, Color.FromArgb(red, green, blue)); } else { brush = new WindowsSolidBrush(graphics.DeviceContext, checkBackground); } try { graphics.FillRectangle(brush, bounds); } finally { if (brush != null) { brush.Dispose(); } } } }
protected void DrawCheckBackgroundFlat(PaintEventArgs e, Rectangle bounds, Color borderColor, Color checkBackground, bool disabledColors) { Color field = checkBackground; Color border = borderColor; if (!Control.Enabled && disabledColors) { border = ControlPaint.ContrastControlDark; field = SystemColors.Control; } float scale = GetDpiScaleRatio(e.Graphics); using( WindowsGraphics wg = WindowsGraphics.FromGraphics(e.Graphics) ) { using( WindowsPen borderPen = new WindowsPen(wg.DeviceContext, border) ) { using( WindowsBrush fieldBrush = new WindowsSolidBrush(wg.DeviceContext, field) ) { // for Dev10 525537, in high DPI mode when we draw ellipse as three rectantles, // the quality of ellipse is poor. Draw it directly as ellipse if(scale > 1.1) { bounds.Width--; bounds.Height--; wg.DrawAndFillEllipse(borderPen, fieldBrush, bounds); bounds.Inflate(-1, -1); } else { DrawAndFillEllipse(wg, borderPen, fieldBrush, bounds); } } } } }
protected void DrawCheckFlat(PaintEventArgs e, LayoutData layout, Color checkColor, Color checkBackground, Color checkBorder, ColorData colors) { Rectangle bounds = layout.checkBounds; // Removed subtracting one for Width and Height. In Everett we needed to do this, // since we were using GDI+ to draw the border. Now that we are using GDI, // we should not do before drawing the border. if (!layout.options.everettButtonCompat) { bounds.Width--; bounds.Height--; } using (WindowsGraphics wg = WindowsGraphics.FromGraphics( e.Graphics )) { using(WindowsPen pen = new WindowsPen(wg.DeviceContext, checkBorder)){ wg.DrawRectangle(pen, bounds); } // Now subtract, since the rest of the code is like Everett. if (layout.options.everettButtonCompat) { bounds.Width--; bounds.Height--; } bounds.Inflate(-1, -1); } if (Control.CheckState == CheckState.Indeterminate) { bounds.Width++; bounds.Height++; DrawDitheredFill(e.Graphics, colors.buttonFace, checkBackground, bounds); } else { using( WindowsGraphics wg = WindowsGraphics.FromGraphics( e.Graphics )) { using (WindowsBrush brush = new WindowsSolidBrush(wg.DeviceContext, checkBackground)) { // Even though we are using GDI here as opposed to GDI+ in Everett, we still need to add 1. bounds.Width++; bounds.Height++; wg.FillRectangle(brush, bounds); } } } DrawCheckOnly(e, layout, colors, checkColor, checkBackground, true); }
protected void DrawCheckOnly(PaintEventArgs e, LayoutData layout, Color checkColor, Color checkBackground, bool disabledColors) { // check // if (Control.Checked) { if (!Control.Enabled && disabledColors) { checkColor = SystemColors.ControlDark; } float scale = GetDpiScaleRatio(e.Graphics); using( WindowsGraphics wg = WindowsGraphics.FromGraphics(e.Graphics) ) { using (WindowsBrush brush = new WindowsSolidBrush(wg.DeviceContext, checkColor)) { // circle drawing doesn't work at this size int offset = 5; Rectangle vCross = new Rectangle (layout.checkBounds.X + GetScaledNumber(offset, scale), layout.checkBounds.Y + GetScaledNumber(offset - 1, scale), GetScaledNumber(2, scale), GetScaledNumber(4, scale)); wg.FillRectangle(brush, vCross); Rectangle hCross = new Rectangle (layout.checkBounds.X + GetScaledNumber(offset - 1, scale), layout.checkBounds.Y + GetScaledNumber(offset, scale), GetScaledNumber(4, scale), GetScaledNumber(2, scale)); wg.FillRectangle(brush, hCross); } } } }
// PaintPrivate is used in three places that need to duplicate the paint code: // 1. DataGridViewCell::Paint method // 2. DataGridViewCell::GetContentBounds // 3. DataGridViewCell::GetErrorIconBounds // // if computeContentBounds is true then PaintPrivate returns the contentBounds // else if computeErrorIconBounds is true then PaintPrivate returns the errorIconBounds // else it returns Rectangle.Empty; private Rectangle PaintPrivate(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, 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); Point ptCurrentCell = this.DataGridView.CurrentCellAddress; bool cellSelected = (elementState & DataGridViewElementStates.Selected) != 0; bool cellCurrent = (ptCurrentCell.X == this.ColumnIndex && ptCurrentCell.Y == rowIndex); Rectangle resultBounds; string formattedString = formattedValue as string; SolidBrush backBrush = this.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && cellSelected) ? cellStyle.SelectionBackColor : cellStyle.BackColor); SolidBrush foreBrush = this.DataGridView.GetCachedBrush(cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor); if (paint && DataGridViewCell.PaintBorder(paintParts)) { PaintBorder(g, 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; if (valBounds.Height > 0 && valBounds.Width > 0) { if (paint && DataGridViewCell.PaintBackground(paintParts) && backBrush.Color.A == 255) { g.FillRectangle(backBrush, valBounds); } if (cellStyle.Padding != Padding.Empty) { if (this.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; if (valBounds.Height > 0 && valBounds.Width > 0 && (paint || computeContentBounds)) { if (this.FlatStyle == FlatStyle.Standard || this.FlatStyle == FlatStyle.System) { if (this.DataGridView.ApplyVisualStylesToInnerCells) { if (paint && DataGridViewCell.PaintContentBackground(paintParts)) { VisualStyles.PushButtonState pbState = VisualStyles.PushButtonState.Normal; if ((this.ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0) { pbState = VisualStyles.PushButtonState.Pressed; } else if (this.DataGridView.MouseEnteredCellAddress.Y == rowIndex && this.DataGridView.MouseEnteredCellAddress.X == this.ColumnIndex && mouseInContentBounds) { pbState = VisualStyles.PushButtonState.Hot; } if (DataGridViewCell.PaintFocus(paintParts) && cellCurrent && this.DataGridView.ShowFocusCues && this.DataGridView.Focused) { pbState |= VisualStyles.PushButtonState.Default; } DataGridViewButtonCellRenderer.DrawButton(g, valBounds, (int)pbState); } resultBounds = valBounds; valBounds = DataGridViewButtonCellRenderer.DataGridViewButtonRenderer.GetBackgroundContentRectangle(g, valBounds); } else { if (paint && DataGridViewCell.PaintContentBackground(paintParts)) { ControlPaint.DrawBorder(g, valBounds, SystemColors.Control, (this.ButtonState == ButtonState.Normal) ? ButtonBorderStyle.Outset : ButtonBorderStyle.Inset); } resultBounds = valBounds; valBounds.Inflate(-SystemInformation.Border3DSize.Width, -SystemInformation.Border3DSize.Height); } } else if (this.FlatStyle == FlatStyle.Flat) { // ButtonBase::PaintFlatDown and ButtonBase::PaintFlatUp paint the border in the same way valBounds.Inflate(-1, -1); if (paint && DataGridViewCell.PaintContentBackground(paintParts)) { ButtonInternal.ButtonBaseAdapter.DrawDefaultBorder(g, valBounds, foreBrush.Color, true /*isDefault == true*/); if (backBrush.Color.A == 255) { if ((this.ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0) { ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintFlatRender(g, cellStyle.ForeColor, cellStyle.BackColor, this.DataGridView.Enabled).Calculate(); IntPtr hdc = g.GetHdc(); try { using( WindowsGraphics wg = WindowsGraphics.FromHdc(hdc)) { System.Windows.Forms.Internal.WindowsBrush windowsBrush; if (colors.options.highContrast) { windowsBrush = new System.Windows.Forms.Internal.WindowsSolidBrush(wg.DeviceContext, colors.buttonShadow); } else { windowsBrush = new System.Windows.Forms.Internal.WindowsSolidBrush(wg.DeviceContext, colors.lowHighlight); } try { ButtonInternal.ButtonBaseAdapter.PaintButtonBackground(wg, valBounds, windowsBrush); } finally { windowsBrush.Dispose(); } } } finally { g.ReleaseHdc(); } } else if (this.DataGridView.MouseEnteredCellAddress.Y == rowIndex && this.DataGridView.MouseEnteredCellAddress.X == this.ColumnIndex && mouseInContentBounds) { IntPtr hdc = g.GetHdc(); try { using( WindowsGraphics wg = WindowsGraphics.FromHdc(hdc)) { Color mouseOverBackColor = SystemColors.ControlDark; using (System.Windows.Forms.Internal.WindowsBrush windowBrush = new System.Windows.Forms.Internal.WindowsSolidBrush(wg.DeviceContext, mouseOverBackColor)) { ButtonInternal.ButtonBaseAdapter.PaintButtonBackground(wg, valBounds, windowBrush); } } } finally { g.ReleaseHdc(); } } } } resultBounds = valBounds; } else { Debug.Assert(this.FlatStyle == FlatStyle.Popup, "FlatStyle.Popup is the last flat style"); valBounds.Inflate(-1, -1); if (paint && DataGridViewCell.PaintContentBackground(paintParts)) { if ((this.ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0) { // paint down ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, this.DataGridView.Enabled).Calculate(); ButtonBaseAdapter.DrawDefaultBorder(g, valBounds, colors.options.highContrast ? colors.windowText : colors.windowFrame, true /*isDefault*/); ControlPaint.DrawBorder(g, valBounds, colors.options.highContrast ? colors.windowText : colors.buttonShadow, ButtonBorderStyle.Solid); } else if (this.DataGridView.MouseEnteredCellAddress.Y == rowIndex && this.DataGridView.MouseEnteredCellAddress.X == this.ColumnIndex && mouseInContentBounds) { // paint over ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, this.DataGridView.Enabled).Calculate(); ButtonBaseAdapter.DrawDefaultBorder(g, valBounds, colors.options.highContrast ? colors.windowText : colors.buttonShadow, false /*isDefault*/); ButtonBaseAdapter.Draw3DLiteBorder(g, valBounds, colors, true); } else { // paint up ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, this.DataGridView.Enabled).Calculate(); ButtonBaseAdapter.DrawDefaultBorder(g, valBounds, colors.options.highContrast ? colors.windowText : colors.buttonShadow, false /*isDefault*/); ButtonBaseAdapter.DrawFlatBorder(g, valBounds, colors.options.highContrast ? colors.windowText : colors.buttonShadow); } } resultBounds = valBounds; } } else if (computeErrorIconBounds) { if (!String.IsNullOrEmpty(errorText)) { resultBounds = ComputeErrorIconBounds(errorBounds); } else { resultBounds = Rectangle.Empty; } } else { Debug.Assert(valBounds.Height <= 0 || valBounds.Width <= 0); resultBounds = Rectangle.Empty; } if (paint && DataGridViewCell.PaintFocus(paintParts) && cellCurrent && this.DataGridView.ShowFocusCues && this.DataGridView.Focused && valBounds.Width > 2 * SystemInformation.Border3DSize.Width + 1 && valBounds.Height > 2 * SystemInformation.Border3DSize.Height + 1) { // Draw focus rectangle if (this.FlatStyle == FlatStyle.System || this.FlatStyle == FlatStyle.Standard) { ControlPaint.DrawFocusRectangle(g, Rectangle.Inflate(valBounds, -1, -1), Color.Empty, SystemColors.Control); } else if (this.FlatStyle == FlatStyle.Flat) { if ((this.ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0 || (this.DataGridView.CurrentCellAddress.Y == rowIndex && this.DataGridView.CurrentCellAddress.X == this.ColumnIndex)) { ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintFlatRender(g, cellStyle.ForeColor, cellStyle.BackColor, this.DataGridView.Enabled).Calculate(); string text = (formattedString != null) ? formattedString : String.Empty; ButtonBaseAdapter.LayoutOptions options = ButtonInternal.ButtonFlatAdapter.PaintFlatLayout(g, true, SystemInformation.HighContrast, 1, valBounds, Padding.Empty, false, cellStyle.Font, text, this.DataGridView.Enabled, DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment), this.DataGridView.RightToLeft); options.everettButtonCompat = false; ButtonBaseAdapter.LayoutData layout = options.Layout(); ButtonInternal.ButtonBaseAdapter.DrawFlatFocus(g, layout.focus, colors.options.highContrast ? colors.windowText : colors.constrastButtonShadow); } } else { Debug.Assert(this.FlatStyle == FlatStyle.Popup, "FlatStyle.Popup is the last flat style"); if ((this.ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0 || (this.DataGridView.CurrentCellAddress.Y == rowIndex && this.DataGridView.CurrentCellAddress.X == this.ColumnIndex)) { // If we are painting the current cell, then paint the text up. // If we are painting the current cell and the current cell is pressed down, then paint the text down. bool paintUp = (this.ButtonState == ButtonState.Normal); string text = (formattedString != null) ? formattedString : String.Empty; ButtonBaseAdapter.LayoutOptions options = ButtonInternal.ButtonPopupAdapter.PaintPopupLayout(g, paintUp, SystemInformation.HighContrast ? 2 : 1, valBounds, Padding.Empty, false, cellStyle.Font, text, this.DataGridView.Enabled, DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment), this.DataGridView.RightToLeft); options.everettButtonCompat = false; ButtonBaseAdapter.LayoutData layout = options.Layout(); ControlPaint.DrawFocusRectangle(g, layout.focus, cellStyle.ForeColor, cellStyle.BackColor); } } } if (formattedString != null && paint && DataGridViewCell.PaintContentForeground(paintParts)) { // Font independent margins valBounds.Offset(DATAGRIDVIEWBUTTONCELL_horizontalTextMargin, DATAGRIDVIEWBUTTONCELL_verticalTextMargin); valBounds.Width -= 2 * DATAGRIDVIEWBUTTONCELL_horizontalTextMargin; valBounds.Height -= 2 * DATAGRIDVIEWBUTTONCELL_verticalTextMargin; if ((this.ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0 && this.FlatStyle != FlatStyle.Flat && this.FlatStyle != FlatStyle.Popup) { valBounds.Offset(1, 1); valBounds.Width--; valBounds.Height--; } if (valBounds.Width > 0 && valBounds.Height > 0) { Color textColor; if (this.DataGridView.ApplyVisualStylesToInnerCells && (this.FlatStyle == FlatStyle.System || this.FlatStyle == FlatStyle.Standard)) { textColor = DataGridViewButtonCellRenderer.DataGridViewButtonRenderer.GetColor(ColorProperty.TextColor); } else { textColor = foreBrush.Color; } TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(this.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode); TextRenderer.DrawText(g, formattedString, cellStyle.Font, valBounds, textColor, flags); } } if (this.DataGridView.ShowCellErrors && paint && DataGridViewCell.PaintErrorIcon(paintParts)) { PaintErrorIcon(g, cellStyle, rowIndex, cellBounds, errorBounds, errorText); } } else { resultBounds = Rectangle.Empty; } return resultBounds; }
protected void DrawCheckBackgroundFlat(PaintEventArgs e, Rectangle bounds, Color borderColor, Color checkBackground, bool disabledColors) { Color control = checkBackground; Color contrastControlDark = borderColor; if (!this.Control.Enabled && disabledColors) { contrastControlDark = ControlPaint.ContrastControlDark; control = SystemColors.Control; } float dpiScaleRatio = CheckableControlBaseAdapter.GetDpiScaleRatio(e.Graphics); using (WindowsGraphics graphics = WindowsGraphics.FromGraphics(e.Graphics)) { using (WindowsPen pen = new WindowsPen(graphics.DeviceContext, contrastControlDark)) { using (WindowsBrush brush = new WindowsSolidBrush(graphics.DeviceContext, control)) { if (dpiScaleRatio > 1.1) { bounds.Width--; bounds.Height--; graphics.DrawAndFillEllipse(pen, brush, bounds); bounds.Inflate(-1, -1); } else { DrawAndFillEllipse(graphics, pen, brush, bounds); } } } } }
protected void DrawCheckOnly(PaintEventArgs e, ButtonBaseAdapter.LayoutData layout, Color checkColor, Color checkBackground, bool disabledColors) { if (this.Control.Checked) { if (!this.Control.Enabled && disabledColors) { checkColor = SystemColors.ControlDark; } float dpiScaleRatio = CheckableControlBaseAdapter.GetDpiScaleRatio(e.Graphics); using (WindowsGraphics graphics = WindowsGraphics.FromGraphics(e.Graphics)) { using (WindowsBrush brush = new WindowsSolidBrush(graphics.DeviceContext, checkColor)) { int n = 5; Rectangle rect = new Rectangle(layout.checkBounds.X + GetScaledNumber(n, dpiScaleRatio), layout.checkBounds.Y + GetScaledNumber(n - 1, dpiScaleRatio), GetScaledNumber(2, dpiScaleRatio), GetScaledNumber(4, dpiScaleRatio)); graphics.FillRectangle(brush, rect); Rectangle rectangle2 = new Rectangle(layout.checkBounds.X + GetScaledNumber(n - 1, dpiScaleRatio), layout.checkBounds.Y + GetScaledNumber(n, dpiScaleRatio), GetScaledNumber(4, dpiScaleRatio), GetScaledNumber(2, dpiScaleRatio)); graphics.FillRectangle(brush, rectangle2); } } } }
internal WindowsSolidBrush GetCachedWindowsBrush(Color color) { WindowsSolidBrush brush = (WindowsSolidBrush)this.brushes[color]; if (brush == null) { brush = new WindowsSolidBrush(color); this.brushes.Add(color, brush); } return brush; }
protected void DrawCheckFlat(PaintEventArgs e, ButtonBaseAdapter.LayoutData layout, Color checkColor, Color checkBackground, Color checkBorder, ButtonBaseAdapter.ColorData colors) { Rectangle checkBounds = layout.checkBounds; if (!layout.options.everettButtonCompat) { checkBounds.Width--; checkBounds.Height--; } using (WindowsGraphics graphics = WindowsGraphics.FromGraphics(e.Graphics)) { using (WindowsPen pen = new WindowsPen(graphics.DeviceContext, checkBorder)) { graphics.DrawRectangle(pen, checkBounds); } if (layout.options.everettButtonCompat) { checkBounds.Width--; checkBounds.Height--; } checkBounds.Inflate(-1, -1); } if (this.Control.CheckState == CheckState.Indeterminate) { checkBounds.Width++; checkBounds.Height++; ButtonBaseAdapter.DrawDitheredFill(e.Graphics, colors.buttonFace, checkBackground, checkBounds); } else { using (WindowsGraphics graphics2 = WindowsGraphics.FromGraphics(e.Graphics)) { using (WindowsBrush brush = new WindowsSolidBrush(graphics2.DeviceContext, checkBackground)) { checkBounds.Width++; checkBounds.Height++; graphics2.FillRectangle(brush, checkBounds); } } } this.DrawCheckOnly(e, layout, colors, checkColor, checkBackground, true); }
private Rectangle PaintPrivate(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, bool computeContentBounds, bool computeErrorIconBounds, bool paint) { Rectangle empty; Point currentCellAddress = base.DataGridView.CurrentCellAddress; bool flag = (elementState & DataGridViewElementStates.Selected) != DataGridViewElementStates.None; bool flag2 = (currentCellAddress.X == base.ColumnIndex) && (currentCellAddress.Y == rowIndex); string text = formattedValue as string; SolidBrush cachedBrush = base.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && flag) ? cellStyle.SelectionBackColor : cellStyle.BackColor); SolidBrush brush2 = base.DataGridView.GetCachedBrush(flag ? cellStyle.SelectionForeColor : cellStyle.ForeColor); if (paint && DataGridViewCell.PaintBorder(paintParts)) { this.PaintBorder(g, 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; if ((rect.Height <= 0) || (rect.Width <= 0)) { return Rectangle.Empty; } if ((paint && DataGridViewCell.PaintBackground(paintParts)) && (cachedBrush.Color.A == 0xff)) { g.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; } Rectangle cellValueBounds = rect; if (((rect.Height <= 0) || (rect.Width <= 0)) || (!paint && !computeContentBounds)) { if (computeErrorIconBounds) { if (!string.IsNullOrEmpty(errorText)) { empty = base.ComputeErrorIconBounds(cellValueBounds); } else { empty = Rectangle.Empty; } } else { empty = Rectangle.Empty; } goto Label_06AD; } if ((this.FlatStyle == System.Windows.Forms.FlatStyle.Standard) || (this.FlatStyle == System.Windows.Forms.FlatStyle.System)) { if (base.DataGridView.ApplyVisualStylesToInnerCells) { if (paint && DataGridViewCell.PaintContentBackground(paintParts)) { PushButtonState normal = PushButtonState.Normal; if ((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal) { normal = PushButtonState.Pressed; } else if (((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == base.ColumnIndex)) && mouseInContentBounds) { normal = PushButtonState.Hot; } if ((DataGridViewCell.PaintFocus(paintParts) && flag2) && (base.DataGridView.ShowFocusCues && base.DataGridView.Focused)) { normal |= PushButtonState.Default; } DataGridViewButtonCellRenderer.DrawButton(g, rect, (int) normal); } empty = rect; rect = DataGridViewButtonCellRenderer.DataGridViewButtonRenderer.GetBackgroundContentRectangle(g, rect); } else { if (paint && DataGridViewCell.PaintContentBackground(paintParts)) { ControlPaint.DrawBorder(g, rect, SystemColors.Control, (this.ButtonState == System.Windows.Forms.ButtonState.Normal) ? ButtonBorderStyle.Outset : ButtonBorderStyle.Inset); } empty = rect; rect.Inflate(-SystemInformation.Border3DSize.Width, -SystemInformation.Border3DSize.Height); } goto Label_06AD; } if (this.FlatStyle != System.Windows.Forms.FlatStyle.Flat) { rect.Inflate(-1, -1); if (paint && DataGridViewCell.PaintContentBackground(paintParts)) { if ((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal) { ButtonBaseAdapter.ColorData data2 = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate(); ButtonBaseAdapter.DrawDefaultBorder(g, rect, data2.options.highContrast ? data2.windowText : data2.windowFrame, true); ControlPaint.DrawBorder(g, rect, data2.options.highContrast ? data2.windowText : data2.buttonShadow, ButtonBorderStyle.Solid); } else if (((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == base.ColumnIndex)) && mouseInContentBounds) { ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate(); ButtonBaseAdapter.DrawDefaultBorder(g, rect, colors.options.highContrast ? colors.windowText : colors.buttonShadow, false); ButtonBaseAdapter.Draw3DLiteBorder(g, rect, colors, true); } else { ButtonBaseAdapter.ColorData data4 = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate(); ButtonBaseAdapter.DrawDefaultBorder(g, rect, data4.options.highContrast ? data4.windowText : data4.buttonShadow, false); ButtonBaseAdapter.DrawFlatBorder(g, rect, data4.options.highContrast ? data4.windowText : data4.buttonShadow); } } empty = rect; goto Label_06AD; } rect.Inflate(-1, -1); if (paint && DataGridViewCell.PaintContentBackground(paintParts)) { ButtonBaseAdapter.DrawDefaultBorder(g, rect, brush2.Color, true); if (cachedBrush.Color.A == 0xff) { if ((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal) { ButtonBaseAdapter.ColorData data = ButtonBaseAdapter.PaintFlatRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate(); IntPtr hdc = g.GetHdc(); try { using (WindowsGraphics graphics = WindowsGraphics.FromHdc(hdc)) { WindowsBrush brush3; if (data.options.highContrast) { brush3 = new WindowsSolidBrush(graphics.DeviceContext, data.buttonShadow); } else { brush3 = new WindowsSolidBrush(graphics.DeviceContext, data.lowHighlight); } try { ButtonBaseAdapter.PaintButtonBackground(graphics, rect, brush3); } finally { brush3.Dispose(); } } goto Label_04CF; } finally { g.ReleaseHdc(); } } if (((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == base.ColumnIndex)) && mouseInContentBounds) { IntPtr hDc = g.GetHdc(); try { using (WindowsGraphics graphics2 = WindowsGraphics.FromHdc(hDc)) { Color controlDark = SystemColors.ControlDark; using (WindowsBrush brush4 = new WindowsSolidBrush(graphics2.DeviceContext, controlDark)) { ButtonBaseAdapter.PaintButtonBackground(graphics2, rect, brush4); } } } finally { g.ReleaseHdc(); } } } } Label_04CF: empty = rect; Label_06AD: if (((paint && DataGridViewCell.PaintFocus(paintParts)) && (flag2 && base.DataGridView.ShowFocusCues)) && ((base.DataGridView.Focused && (rect.Width > ((2 * SystemInformation.Border3DSize.Width) + 1))) && (rect.Height > ((2 * SystemInformation.Border3DSize.Height) + 1)))) { if ((this.FlatStyle == System.Windows.Forms.FlatStyle.System) || (this.FlatStyle == System.Windows.Forms.FlatStyle.Standard)) { ControlPaint.DrawFocusRectangle(g, Rectangle.Inflate(rect, -1, -1), Color.Empty, SystemColors.Control); } else if (this.FlatStyle == System.Windows.Forms.FlatStyle.Flat) { if (((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal) || ((base.DataGridView.CurrentCellAddress.Y == rowIndex) && (base.DataGridView.CurrentCellAddress.X == base.ColumnIndex))) { ButtonBaseAdapter.ColorData data5 = ButtonBaseAdapter.PaintFlatRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate(); string str2 = (text != null) ? text : string.Empty; ButtonBaseAdapter.LayoutOptions options = ButtonFlatAdapter.PaintFlatLayout(g, true, SystemInformation.HighContrast, 1, rect, Padding.Empty, false, cellStyle.Font, str2, base.DataGridView.Enabled, DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment), base.DataGridView.RightToLeft); options.everettButtonCompat = false; ButtonBaseAdapter.LayoutData data6 = options.Layout(); ButtonBaseAdapter.DrawFlatFocus(g, data6.focus, data5.options.highContrast ? data5.windowText : data5.constrastButtonShadow); } } else if (((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal) || ((base.DataGridView.CurrentCellAddress.Y == rowIndex) && (base.DataGridView.CurrentCellAddress.X == base.ColumnIndex))) { bool up = this.ButtonState == System.Windows.Forms.ButtonState.Normal; string str3 = (text != null) ? text : string.Empty; ButtonBaseAdapter.LayoutOptions options2 = ButtonPopupAdapter.PaintPopupLayout(g, up, SystemInformation.HighContrast ? 2 : 1, rect, Padding.Empty, false, cellStyle.Font, str3, base.DataGridView.Enabled, DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment), base.DataGridView.RightToLeft); options2.everettButtonCompat = false; ButtonBaseAdapter.LayoutData data7 = options2.Layout(); ControlPaint.DrawFocusRectangle(g, data7.focus, cellStyle.ForeColor, cellStyle.BackColor); } } if (((text != null) && paint) && DataGridViewCell.PaintContentForeground(paintParts)) { rect.Offset(2, 1); rect.Width -= 4; rect.Height -= 2; if ((((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal) && (this.FlatStyle != System.Windows.Forms.FlatStyle.Flat)) && (this.FlatStyle != System.Windows.Forms.FlatStyle.Popup)) { rect.Offset(1, 1); rect.Width--; rect.Height--; } if ((rect.Width > 0) && (rect.Height > 0)) { Color color; if (base.DataGridView.ApplyVisualStylesToInnerCells && ((this.FlatStyle == System.Windows.Forms.FlatStyle.System) || (this.FlatStyle == System.Windows.Forms.FlatStyle.Standard))) { color = DataGridViewButtonCellRenderer.DataGridViewButtonRenderer.GetColor(ColorProperty.TextColor); } else { color = brush2.Color; } TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(base.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode); TextRenderer.DrawText(g, text, cellStyle.Font, rect, color, flags); } } if ((base.DataGridView.ShowCellErrors && paint) && DataGridViewCell.PaintErrorIcon(paintParts)) { base.PaintErrorIcon(g, cellStyle, rowIndex, cellBounds, cellValueBounds, errorText); } return empty; }
// used by DataGridViewCheckBoxCell internal static void DrawCheckBackground(bool controlEnabled, CheckState controlCheckState, Graphics g, Rectangle bounds, Color checkColor, Color checkBackground, bool disabledColors, ColorData colors) { using ( WindowsGraphics wg = WindowsGraphics.FromGraphics( g )) { WindowsBrush brush; if (!controlEnabled && disabledColors) { brush = new WindowsSolidBrush(wg.DeviceContext, SystemColors.Control); } else if (controlCheckState == CheckState.Indeterminate && checkBackground == SystemColors.Window && disabledColors) { Color comboColor = SystemInformation.HighContrast ? SystemColors.ControlDark : SystemColors.Control; byte R = (byte)((comboColor.R + SystemColors.Window.R) / 2); byte G = (byte)((comboColor.G + SystemColors.Window.G) / 2); byte B = (byte)((comboColor.B + SystemColors.Window.B) / 2); brush = new WindowsSolidBrush(wg.DeviceContext, Color.FromArgb(R, G, B)); } else { brush = new WindowsSolidBrush(wg.DeviceContext, checkBackground); } try { wg.FillRectangle(brush, bounds); } finally { if (brush != null) { brush.Dispose(); } } } }