protected override void OnPaint(PaintEventArgs e) { if (!this.DesignMode && this.UseTheme && PluginBase.MainForm.GetThemeColor("CheckBox.BackColor") != Color.Empty) { Size size = SystemInformation.MenuCheckSize; var offset = (this.ClientRectangle.Height - 1) - size.Height; var flags = TextFormatFlags.Left | TextFormatFlags.VerticalCenter; var checkRect = new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y + offset, size.Width - 2, size.Height - 2); var innerRect = new Rectangle(this.ClientRectangle.X + 3, this.ClientRectangle.Y + offset + 3, size.Width - 7, size.Height - 7); var textRect = new Rectangle(this.ClientRectangle.Location, this.ClientRectangle.Size); if (this.RightToLeft == RightToLeft.Yes) { offset = this.ClientRectangle.Width - size.Width; flags = TextFormatFlags.Right | TextFormatFlags.VerticalCenter; textRect.Offset(-size.Width, 0); checkRect.Offset(offset, 0); } else { textRect.Offset(checkRect.Width + 3, 0); } Color back = this.FlatAppearance.CheckedBackColor; if (ClientRectangle.Contains(PointToClient(MousePosition))) { if (MouseButtons == MouseButtons.Left) { back = this.FlatAppearance.MouseDownBackColor; } else { back = this.FlatAppearance.MouseOverBackColor; } } ButtonRenderer.DrawParentBackground(e.Graphics, this.ClientRectangle, this); e.Graphics.FillRectangle(new SolidBrush(this.BackColor), this.ClientRectangle); e.Graphics.FillRectangle(new SolidBrush(back), checkRect); e.Graphics.DrawRectangle(new Pen(this.BorderColor), checkRect); if (this.CheckState == CheckState.Indeterminate) { e.Graphics.FillRectangle(new SolidBrush(this.BackColor), innerRect); } else if (this.CheckState == CheckState.Checked) { Image image = PluginBase.MainForm.FindImageAndSetAdjust("485"); e.Graphics.DrawImage(image, checkRect, new Rectangle(Point.Empty, image.Size), GraphicsUnit.Pixel); } TextRenderer.DrawText(e.Graphics, this.Text, this.Font, textRect, this.ForeColor, flags); } else { base.OnPaint(e); } }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { // The button cell is disabled, so paint the border, // background, and disabled button for the cell. if (!this.enabledValue) { // Draw the cell background, if specified. if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background) { SolidBrush cellBackground = new SolidBrush(cellStyle.BackColor); graphics.FillRectangle(cellBackground, cellBounds); cellBackground.Dispose(); } // Draw the cell borders, if specified. if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border) { PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } // Calculate the area in which to draw the button. Rectangle buttonArea = cellBounds; Rectangle buttonAdjustment = this.BorderWidths(advancedBorderStyle); buttonArea.X += buttonAdjustment.X; buttonArea.Y += buttonAdjustment.Y; buttonArea.Height -= buttonAdjustment.Height; buttonArea.Width -= buttonAdjustment.Width; // Draw the disabled button. ButtonRenderer.DrawButton(graphics, buttonArea, PushButtonState.Disabled); // Draw the disabled button text. if (this.FormattedValue is String) { TextRenderer.DrawText(graphics, (string)this.FormattedValue, this.DataGridView.Font, buttonArea, SystemColors.GrayText); } } else { // The button cell is enabled, so let the base class // handle the painting. base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); } }
internal override void PaintPartBackground(Graphics graphics, Rectangle cellBounds, DataGridViewCellStyle style) { ButtonRenderer.DrawButton(graphics, cellBounds, button_state); }