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) { var buttonRectangle = new Rectangle(cellBounds.X + 2, cellBounds.Y + 2, cellBounds.Width - 4, cellBounds.Height - 4); base.Paint(graphics, clipBounds, buttonRectangle, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); var imageRectangle = new Rectangle(cellBounds.X + 6, cellBounds.Y + 6, _detailImage.Width, _detailImage.Height); graphics.DrawImage(_detailImage, imageRectangle); }
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 base Paint implementation paints the check box base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); // Get the check box bounds: they are the content bounds Rectangle contentBounds = this.GetContentBounds(rowIndex); // Compute the location where we want to paint the string. Point stringLocation = new Point(); // Compute the Y. // NOTE: the current logic does not take into account padding. stringLocation.Y = cellBounds.Y + 2; // Compute the X. // Content bounds are computed relative to the cell bounds // - not relative to the DataGridView control. stringLocation.X = cellBounds.X + contentBounds.Right + 2; // Paint the string. if (this.Label == null) { DataGridViewCheckBoxWithLabelColumn col = (DataGridViewCheckBoxWithLabelColumn) this.OwningColumn; this.label = col.Label; } graphics.DrawString(this.Label, Control.DefaultFont, System.Drawing.Brushes.Red, stringLocation); }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { if (this.DataGridView == null) { return; } // First paint the borders and background of the cell. base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts & ~(DataGridViewPaintParts.ErrorIcon | DataGridViewPaintParts.ContentForeground)); IRulesBoxLine myLine = Value as IRulesBoxLine; myLine.Selected = this.Selected; myLine.Paint(graphics, cellStyle.Font, cellBounds.Left, cellBounds.Top); }
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) { var fillRectangle = new Rectangle(cellBounds.X, cellBounds.Y, cellBounds.Width - 1, cellBounds.Height - 1); var stringRectangle = new Rectangle(cellBounds.X + 5, cellBounds.Y + 3, cellBounds.Width - 8, cellBounds.Height - 8); graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.FillRectangle(new SolidBrush(Color.FromArgb(215, 228, 242)), fillRectangle); graphics.DrawLine(new Pen(Color.FromArgb(153, 180, 209), 1), new Point(cellBounds.X + cellBounds.Width - 1, cellBounds.Y), new Point(cellBounds.X + cellBounds.Width - 1, cellBounds.Y + cellBounds.Height - 1)); graphics.DrawLine(new Pen(Color.FromArgb(153, 180, 209), 1), new Point(cellBounds.X, cellBounds.Y + cellBounds.Height - 1), new Point(cellBounds.X + cellBounds.Width - 1, cellBounds.Y + cellBounds.Height - 1)); //var pen = new Pen(new LinearGradientBrush(new Rectangle(1, 1, 1, 1), // Color.FromArgb(0, 0, 0), // Color.FromArgb(200, 200, 200), // LinearGradientMode.Horizontal)) //{ // DashCap = DashCap.Round, // Width = 1 //}; //graphics.DrawLine(pen, // new Point(cellBounds.X + 7, cellBounds.Y + 7), // new Point(cellBounds.X + cellBounds.Width - 7, cellBounds.Y + cellBounds.Height - 7)); //graphics.DrawLine(pen, // new Point(cellBounds.X + cellBounds.Width - 7, cellBounds.Y + 7), // new Point(cellBounds.X + 7, cellBounds.Y + cellBounds.Height - 7)); graphics.DrawString("X", new Font("Comic Sans MS", 9.0f, FontStyle.Regular), new SolidBrush(Color.FromArgb(0, 0, 0)), stringRectangle); }
protected override void Paint(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { try { int progressVal = (int)value; float percentage = ((float)progressVal / 100.0f); // Need to convert to float before division; otherwise C# returns int which is 0 for anything but 100%. // Draws the cell grid base.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground)); // Draw the progress bar and the text g.FillRectangle(new SolidBrush(Color.FromArgb(8, 142, 6)), cellBounds.X + 2, cellBounds.Y + 2, Convert.ToInt32((percentage * cellBounds.Width - 4)), cellBounds.Height - 4); string text = Value.ToString() + "%"; Font f = cellStyle.Font; SizeF len = g.MeasureString(text, f); SolidBrush foreColor = new SolidBrush(cellStyle.ForeColor); if (DataGridView.Rows[rowIndex].Selected) foreColor = new SolidBrush(cellStyle.SelectionForeColor); Point location = new Point(Convert.ToInt32(cellBounds.X + ((cellBounds.Width / 2) - len.Width / 2)), Convert.ToInt32(cellBounds.Y + ((cellBounds.Height / 2) - len.Height / 2))); g.DrawString(text, f, foreColor, location); } catch (Exception ex) { logger.Error(ex, "Error painting cell"); } }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { if (Columns.Count > rowIndex) { Column c = Columns[rowIndex]; if (c.PrimaryKey) { Bitmap bmp = rowIndex == DataGridView.CurrentRow.Index ? Resources.ArrowKey : Resources.Key; bmp.MakeTransparent(); paintParts &= ~DataGridViewPaintParts.ContentBackground; base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); Rectangle r = cellBounds; r.Offset(bmp.Width / 2, bmp.Height / 2); r.Width = bmp.Width; r.Height = bmp.Height; graphics.DrawImage(bmp, r); return; } } base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); }
protected override void Paint( Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { // Call the base class method to paint the default cell appearance. base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); // Retrieve the client location of the mouse pointer. Point cursorPosition = this.DataGridView.PointToClient(Cursor.Position); // If the mouse pointer is over the current cell, draw a custom border. if (cellBounds.Contains(cursorPosition)) { Rectangle newRect = new Rectangle(cellBounds.X + 1, cellBounds.Y + 1, cellBounds.Width - 4, cellBounds.Height - 4); graphics.DrawRectangle(Pens.Red, newRect); } }
//绘制列头checkbox protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); Point p = new Point(); Size s = CheckBoxRenderer.GetGlyphSize(graphics, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal); p.X = cellBounds.Location.X + (cellBounds.Width / 2) - (s.Width / 2) - 1;//列头checkbox的X坐标 p.Y = cellBounds.Location.Y + (cellBounds.Height / 2) - (s.Height / 2);//列头checkbox的Y坐标 _cellLocation = cellBounds.Location; checkBoxLocation = p; checkBoxSize = s; if (_checked) _cbState = CheckBoxState.CheckedNormal; else _cbState = CheckBoxState.UncheckedNormal; CheckBoxRenderer.DrawCheckBox(graphics, checkBoxLocation, _cbState); }
protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { try { string text = value == null ? "" : (string)value; Brush backColorBrush = new SolidBrush(cellStyle.BackColor); Brush foreColorBrush = new SolidBrush(cellStyle.ForeColor); var col = this.OwningColumn as DataGridViewColorMarkColumn; Color markcolor = cellStyle.ForeColor; bool hasmark = col.GetColorMark(rowIndex, out markcolor); Brush markColorBrush = new SolidBrush(markcolor); base.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground)); int rsz = this.DataGridView.RowTemplate.Height - 8; int dy = (cellBounds.Height - this.DataGridView.RowTemplate.Height) / 2; g.FillEllipse(markColorBrush, cellBounds.X + 2, cellBounds.Y + 4 + dy, rsz, rsz); //g.FillRectangle(markColorBrush, cellBounds.X + 2, cellBounds.Y + 4, rsz, rsz); g.DrawString(text, cellStyle.Font, foreColorBrush, cellBounds.X + 4 + rsz, cellBounds.Y + 2 + dy); } catch (Exception e) { } }
protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { Tuple<int, string> updateInfo = (Tuple<int, string>)value; int progressVal = updateInfo.Item1; string message = updateInfo.Item2; float percentage = ((float)progressVal / 100.0f); // Need to convert to float before division; otherwise C# returns int which is 0 for anything but 100%. Brush backColorBrush = new SolidBrush(cellStyle.BackColor); Brush foreColorBrush = new SolidBrush(cellStyle.ForeColor); // Draws the cell grid base.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground)); if (percentage > 0.0) { // Draw the progress bar and the text g.FillRectangle(new SolidBrush(Color.FromArgb(163, 189, 242)), cellBounds.X + 2, cellBounds.Y + 2, Convert.ToInt32((percentage * cellBounds.Width - 4)), cellBounds.Height - 4); g.DrawString(message, cellStyle.Font, foreColorBrush, cellBounds.X + 6, cellBounds.Y + 2); } else { // draw the text if (this.DataGridView.CurrentRow.Index == rowIndex) g.DrawString(message, cellStyle.Font, new SolidBrush(cellStyle.SelectionForeColor), cellBounds.X + 6, cellBounds.Y + 2); else g.DrawString(message, cellStyle.Font, foreColorBrush, cellBounds.X + 6, cellBounds.Y + 2); } }
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, enabledValue ? SystemColors.ControlText : 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); } }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); graphics.FillRectangle(new SolidBrush(cellStyle.BackColor), cellBounds); CheckBoxRegion = new Rectangle( cellBounds.Location.X + 1, cellBounds.Location.Y + 2, 25, cellBounds.Size.Height - 4); if (this.checkAll) ControlPaint.DrawCheckBox(graphics, CheckBoxRegion, ButtonState.Checked); else ControlPaint.DrawCheckBox(graphics, CheckBoxRegion, ButtonState.Normal); Rectangle normalRegion = new Rectangle( cellBounds.Location.X + 1 + 25, cellBounds.Location.Y, cellBounds.Size.Width - 26, cellBounds.Size.Height); graphics.DrawString(value.ToString(), cellStyle.Font, new SolidBrush(cellStyle.ForeColor), normalRegion); }
protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { try { int progressVal = (int)value; if(progressVal < 0) progressVal = 0; if(progressVal > 100) progressVal = 100; float percentage = ((float)progressVal / 100.0f); Brush backColorBrush = new SolidBrush(cellStyle.BackColor); Brush foreColorBrush = new SolidBrush(cellStyle.ForeColor); Brush barColorBrush = new SolidBrush(GetColorBetween(cellStyle.BackColor, cellStyle.ForeColor, progressVal == 100 ? 0.2f : 0.3f)); base.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground)); var s = progressVal.ToString() + "%"; var sz = g.MeasureString(s, cellStyle.Font); int dy = (cellBounds.Height - this.DataGridView.RowTemplate.Height) / 2; g.FillRectangle(barColorBrush, cellBounds.X + 2, cellBounds.Y + 2, Convert.ToInt32((percentage * cellBounds.Width - 4)), cellBounds.Height - 4); g.DrawString(s, cellStyle.Font, foreColorBrush, cellBounds.X + (cellBounds.Width / 2) - sz.Width / 2 - 5, cellBounds.Y + 2 + dy); } catch (Exception e) { } }
public DataGridViewCellPaintingEventArgs(DataGridView dataGridView, System.Drawing.Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, int columnIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { if (dataGridView == null) { throw new ArgumentNullException("dataGridView"); } if (graphics == null) { throw new ArgumentNullException("graphics"); } if (cellStyle == null) { throw new ArgumentNullException("cellStyle"); } if ((paintParts & ~DataGridViewPaintParts.All) != DataGridViewPaintParts.None) { throw new ArgumentException(System.Windows.Forms.SR.GetString("DataGridView_InvalidDataGridViewPaintPartsCombination", new object[] { "paintParts" })); } this.graphics = graphics; this.clipBounds = clipBounds; this.cellBounds = cellBounds; this.rowIndex = rowIndex; this.columnIndex = columnIndex; this.cellState = cellState; this.value = value; this.formattedValue = formattedValue; this.errorText = errorText; this.cellStyle = cellStyle; this.advancedBorderStyle = advancedBorderStyle; this.paintParts = paintParts; }
protected override void Paint(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { int progressVal = 0; string label = String.Empty; // get progress values if (value != null && value.GetType() == typeof(ProgressState)) { ProgressState s = (ProgressState)value; progressVal = s.CurrentValue; label = s.CurrentState; if (s.ShowProgressBar == false || String.IsNullOrEmpty(label) == false) progressVal = 0; if (s.HasError) this.ErrorText = s.ErrorText; } // Draws the cell grid base.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground)); // draw progress bar float percentage = ((float)progressVal / 100.0f); // Need to convert to float before division; otherwise C# returns int which is 0 for anything but 100%. if (percentage > 0.0) { using (Brush highlightBrush = new SolidBrush(SystemColors.Highlight)) g.FillRectangle(highlightBrush, cellBounds.X + 2, cellBounds.Y + 2, Convert.ToInt32((percentage * cellBounds.Width - 4)), cellBounds.Height - 4); } // draw text if (String.IsNullOrEmpty(label) == false) { using (Brush foreColorBrush = new SolidBrush(cellStyle.ForeColor)) g.DrawString(label, cellStyle.Font, foreColorBrush, cellBounds.X + 6, cellBounds.Y + 4); } }
private void PaintBackGround(Graphics graphics, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewCellStyle cellStyle, Rectangle cellBounds) { Rectangle rectangle = base.BorderWidths(advancedBorderStyle); Rectangle rect = cellBounds; rect.Offset(rectangle.X, rectangle.Y); rect.Width -= rectangle.Right; rect.Height -= rectangle.Bottom; using(SolidBrush brush = new SolidBrush(cellStyle.BackColor)) { graphics.FillRectangle(brush, rect); } if(this.lFileSize <= 0L) { return; } Rectangle bounds = rect; double num = ((double)this.progressValue) / ((double)this.lFileSize); bounds.Width = (int)(bounds.Width * num); if(VisualStyleRenderer.IsSupported) { try { new VisualStyleRenderer(VisualStyleElement.ProgressBar.Chunk.Normal).DrawBackground(graphics, bounds); goto Label_00E1; } catch { goto Label_00E1; } } using(SolidBrush brush2 = new SolidBrush(SystemColors.Highlight)) { graphics.FillRectangle(brush2, bounds); } Label_00E1: using(StringFormat format = new StringFormat()) { format.Alignment = format.LineAlignment = StringAlignment.Center; using(SolidBrush brush3 = new SolidBrush(cellStyle.ForeColor)) { graphics.DrawString(((int)(num * 100.0)) + "%", cellStyle.Font, brush3, rect, format); } } }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { if(this.fNowCalculating) { this.PaintBackGround(graphics, advancedBorderStyle, cellStyle, cellBounds); paintParts &= ~(DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.Background); } base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { graphics.FillRectangle(new SolidBrush(SystemColors.Control), cellBounds); if (DataGridView.SelectedCells.Count > 0 && (DataGridView.SelectedCells[0].ColumnIndex == ColumnIndex || DataGridView.SelectedCells[0].RowIndex == RowIndex)) { ControlPaint.DrawBorder(graphics, cellBounds, SystemColors.ControlDarkDark, 1, ButtonBorderStyle.Solid, SystemColors.ControlDarkDark, 1, ButtonBorderStyle.Solid, SystemColors.ButtonFace, 1, ButtonBorderStyle.Solid, SystemColors.ButtonFace, 1, ButtonBorderStyle.Solid); } else { ControlPaint.DrawBorder(graphics, cellBounds, SystemColors.ButtonHighlight, 1, ButtonBorderStyle.Solid, SystemColors.ButtonHighlight, 1, ButtonBorderStyle.Solid, SystemColors.ControlDarkDark, 1, ButtonBorderStyle.Solid, SystemColors.ControlDarkDark, 1, ButtonBorderStyle.Solid); graphics.DrawLine(SystemPens.ButtonFace, cellBounds.Left, cellBounds.Bottom, cellBounds.Left, cellBounds.Bottom); } var bounds = cellBounds; bounds.Inflate(-2, -2); TextRenderer.DrawText(graphics, (string)formattedValue, cellStyle.Font, bounds, cellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Left); }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { if (Image != null) { base.Paint(graphics, clipBounds, new Rectangle(cellBounds.X + Image.Width, cellBounds.Y, cellBounds.Width - Image.Height,cellBounds.Height), rowIndex, cellState, value, formattedValue,errorText, cellStyle, advancedBorderStyle, paintParts); if ((cellState & DataGridViewElementStates.Selected) != 0) { graphics.FillRectangle( new SolidBrush(this.DataGridView.DefaultCellStyle.SelectionBackColor) , cellBounds.X, cellBounds.Y, Image.Width, cellBounds.Height); } else { graphics.FillRectangle(new SolidBrush(this.DataGridView.DefaultCellStyle.BackColor), cellBounds.X, cellBounds.Y, Image.Width, cellBounds.Height); } graphics.DrawImage(Image, cellBounds.X, cellBounds.Y+2, Image.Width, Math.Min(Image.Height,cellBounds.Height)); } else { base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// </summary> /// <param name="graphics">The <see cref="T:System.Drawing.Graphics"/> used to paint /// the <see cref="T:System.Windows.Forms.DataGridViewCell"/>.</param> /// <param name="clipBounds">A <see cref="T:System.Drawing.Rectangle"/> that represents /// the area of the <see cref="T:System.Windows.Forms.DataGridView"/> that needs to be /// repainted.</param> /// <param name="cellBounds">A <see cref="T:System.Drawing.Rectangle"/> that contains /// the bounds of the <see cref="T:System.Windows.Forms.DataGridViewCell"/> that is /// being painted.</param> /// <param name="rowIndex">The row index of the cell that is being painted.</param> /// <param name="elementState"></param> /// <param name="value">The data of the <see cref="T:System.Windows.Forms.DataGridViewCell"/> /// that is being painted.</param> /// <param name="formattedValue">The formatted data of the /// <see cref="T:System.Windows.Forms.DataGridViewCell"/> that is being painted.</param> /// <param name="errorText">An error message that is associated with the cell.</param> /// <param name="cellStyle">A <see cref="T:System.Windows.Forms.DataGridViewCellStyle"/> /// that contains formatting and style information about the cell.</param> /// <param name="advancedBorderStyle">A /// <see cref="T:System.Windows.Forms.DataGridViewAdvancedBorderStyle"/> that contains /// border styles for the cell that is being painted.</param> /// <param name="paintParts">A bitwise combination of the /// <see cref="T:System.Windows.Forms.DataGridViewPaintParts"/> values that specifies /// which parts of the cell need to be painted.</param> /// ------------------------------------------------------------------------------------ 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) { Bitmap bitmap = formattedValue as Bitmap; if (bitmap == null || !(OwningColumn is CheckGridStatusColumn)) { // We don't know enough to paint this cell, so we let the base class handle it. base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); return; } // Let base class paint everything except content base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts & ~(DataGridViewPaintParts.ContentForeground | DataGridViewPaintParts.Background)); Rectangle cellValueBounds = cellBounds; Rectangle borderRect = BorderWidths(advancedBorderStyle); cellValueBounds.Offset(borderRect.X, borderRect.Y); cellValueBounds.Width -= borderRect.Right; cellValueBounds.Height -= borderRect.Bottom; if (cellValueBounds.Width <= 0 || cellValueBounds.Height <= 0) return; if ((paintParts & DataGridViewPaintParts.Background) != 0) { bool fSelected = (elementState & DataGridViewElementStates.Selected) != 0; Color color = (fSelected & (paintParts & DataGridViewPaintParts.SelectionBackground) != 0) ? cellStyle.SelectionBackColor : cellStyle.BackColor; graphics.FillRectangle(GetCachedBrush(color), cellValueBounds); } if ((paintParts & DataGridViewPaintParts.ContentForeground) != 0) { // scale the image according to zoom factor float zoomFactor = ((CheckGridStatusColumn)OwningColumn).ZoomFactor; int zoomedImageWidth = (int)(bitmap.Width * zoomFactor); int zoomedImageHeight = (int)(bitmap.Height * zoomFactor); Rectangle drawRect = new Rectangle( cellValueBounds.X + (cellValueBounds.Width - zoomedImageWidth) / 2, cellValueBounds.Y + (cellValueBounds.Height - zoomedImageHeight) / 2, zoomedImageWidth, zoomedImageHeight); Region clip = graphics.Clip; graphics.SetClip(Rectangle.Intersect(Rectangle.Intersect(drawRect, cellValueBounds), Rectangle.Truncate(graphics.VisibleClipBounds))); graphics.DrawImage(bitmap, drawRect); graphics.Clip = clip; ICornerGlyphGrid owningGrid = DataGridView as ICornerGlyphGrid; if (owningGrid != null && owningGrid.ShouldDrawCornerGlyph(ColumnIndex, rowIndex)) DrawCornerGlyph(graphics, rowIndex, cellBounds); } }
public virtual DataGridViewAdvancedBorderStyle AdjustCellBorderStyle(DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStyleInput, DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow) { switch (dataGridViewAdvancedBorderStyleInput.All) { case DataGridViewAdvancedCellBorderStyle.NotSet: if ((base.DataGridView != null) && (base.DataGridView.AdvancedCellBorderStyle == dataGridViewAdvancedBorderStyleInput)) { switch (base.DataGridView.CellBorderStyle) { case DataGridViewCellBorderStyle.SingleVertical: if (base.DataGridView.RightToLeftInternal) { dataGridViewAdvancedBorderStylePlaceholder.LeftInternal = DataGridViewAdvancedCellBorderStyle.Single; dataGridViewAdvancedBorderStylePlaceholder.RightInternal = (isFirstDisplayedColumn && singleVerticalBorderAdded) ? DataGridViewAdvancedCellBorderStyle.Single : DataGridViewAdvancedCellBorderStyle.None; } else { dataGridViewAdvancedBorderStylePlaceholder.LeftInternal = (isFirstDisplayedColumn && singleVerticalBorderAdded) ? DataGridViewAdvancedCellBorderStyle.Single : DataGridViewAdvancedCellBorderStyle.None; dataGridViewAdvancedBorderStylePlaceholder.RightInternal = DataGridViewAdvancedCellBorderStyle.Single; } dataGridViewAdvancedBorderStylePlaceholder.TopInternal = DataGridViewAdvancedCellBorderStyle.None; dataGridViewAdvancedBorderStylePlaceholder.BottomInternal = DataGridViewAdvancedCellBorderStyle.None; return dataGridViewAdvancedBorderStylePlaceholder; case DataGridViewCellBorderStyle.SingleHorizontal: dataGridViewAdvancedBorderStylePlaceholder.LeftInternal = DataGridViewAdvancedCellBorderStyle.None; dataGridViewAdvancedBorderStylePlaceholder.RightInternal = DataGridViewAdvancedCellBorderStyle.None; dataGridViewAdvancedBorderStylePlaceholder.TopInternal = (isFirstDisplayedRow && singleHorizontalBorderAdded) ? DataGridViewAdvancedCellBorderStyle.Single : DataGridViewAdvancedCellBorderStyle.None; dataGridViewAdvancedBorderStylePlaceholder.BottomInternal = DataGridViewAdvancedCellBorderStyle.Single; return dataGridViewAdvancedBorderStylePlaceholder; } } return dataGridViewAdvancedBorderStyleInput; case DataGridViewAdvancedCellBorderStyle.None: return dataGridViewAdvancedBorderStyleInput; case DataGridViewAdvancedCellBorderStyle.Single: if ((base.DataGridView == null) || !base.DataGridView.RightToLeftInternal) { dataGridViewAdvancedBorderStylePlaceholder.LeftInternal = (isFirstDisplayedColumn && singleVerticalBorderAdded) ? DataGridViewAdvancedCellBorderStyle.Single : DataGridViewAdvancedCellBorderStyle.None; dataGridViewAdvancedBorderStylePlaceholder.RightInternal = DataGridViewAdvancedCellBorderStyle.Single; break; } dataGridViewAdvancedBorderStylePlaceholder.LeftInternal = DataGridViewAdvancedCellBorderStyle.Single; dataGridViewAdvancedBorderStylePlaceholder.RightInternal = (isFirstDisplayedColumn && singleVerticalBorderAdded) ? DataGridViewAdvancedCellBorderStyle.Single : DataGridViewAdvancedCellBorderStyle.None; break; case DataGridViewAdvancedCellBorderStyle.OutsetPartial: return dataGridViewAdvancedBorderStyleInput; default: return dataGridViewAdvancedBorderStyleInput; } dataGridViewAdvancedBorderStylePlaceholder.TopInternal = (isFirstDisplayedRow && singleHorizontalBorderAdded) ? DataGridViewAdvancedCellBorderStyle.Single : DataGridViewAdvancedCellBorderStyle.None; dataGridViewAdvancedBorderStylePlaceholder.BottomInternal = DataGridViewAdvancedCellBorderStyle.Single; return dataGridViewAdvancedBorderStylePlaceholder; }
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) { 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 != null && this.FormattedValue is String) { TextRenderer.DrawText(graphics, (string)this.FormattedValue, this.DataGridView.Font, buttonArea, SystemColors.GrayText); } } else { System.Reflection.Assembly thisExe = System.Reflection.Assembly.GetExecutingAssembly(); System.IO.Stream file; file = thisExe.GetManifestResourceStream("BiologyDepartment.Misc_Files.images.editicon16.png"); ImageList imgList = new ImageList(); imgList.ImageSize = new System.Drawing.Size(16, 16); imgList.Images.Add(Image.FromStream(file)); base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); graphics.DrawImage(imgList.Images[0], cellBounds); } }
public CustomDataGridViewCell() : base() { _style = new DataGridViewAdvancedBorderStyle(); _style.Bottom = DataGridViewAdvancedCellBorderStyle.None; _style.Top = DataGridViewAdvancedCellBorderStyle.InsetDouble; _style.Left = DataGridViewAdvancedCellBorderStyle.InsetDouble; _style.Right = DataGridViewAdvancedCellBorderStyle.InsetDouble; }
/// <summary> /// 重写样式 /// </summary> /// <param name="graphics"></param> /// <param name="clipBounds"></param> /// <param name="cellBounds"></param> /// <param name="rowIndex"></param> /// <param name="cellState"></param> /// <param name="value"></param> /// <param name="formattedValue"></param> /// <param name="errorText"></param> /// <param name="cellStyle"></param> /// <param name="advancedBorderStyle"></param> /// <param name="paintParts"></param> protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); //Point cursorPositon = this.DataGridView.PointToClient(Cursor.Position); //if (cellBounds.Contains(cursorPositon)) //{ // Rectangle newRect = new Rectangle(cellBounds.X + 1, cellBounds.Y + 1, cellBounds.Width - 4, cellBounds.Height - 4); // graphics.DrawRectangle(Pens.Red, newRect); //} }
public CustomDataGridViewCell() : base() { _style = new DataGridViewAdvancedBorderStyle(); _style.Bottom = DataGridViewAdvancedCellBorderStyle.None; _style.Top = DataGridViewAdvancedCellBorderStyle.InsetDouble; _style.Left = DataGridViewAdvancedCellBorderStyle.InsetDouble; _style.Right = DataGridViewAdvancedCellBorderStyle.InsetDouble; }
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { Point cursorPos = this.DataGridView.PointToClient(Cursor.Position); //if (cellBounds.Contains(cursorPos)) if (Selected) base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); else { graphics.FillRectangle(Brushes.LightGray, cellBounds); } }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, [CanBeNull] object value, [CanBeNull] object formattedValue, [CanBeNull] string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { Guard.NotNull(graphics, nameof(graphics)); Guard.NotNull(cellStyle, nameof(cellStyle)); Guard.NotNull(advancedBorderStyle, nameof(advancedBorderStyle)); if (!Enabled) { if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background) { using (var cellBackground = new SolidBrush(cellStyle.BackColor)) { graphics.FillRectangle(cellBackground, cellBounds); } } if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border) { PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } Rectangle buttonArea = cellBounds; Rectangle buttonAdjustment = BorderWidths(advancedBorderStyle); buttonArea.X += buttonAdjustment.X; buttonArea.Y += buttonAdjustment.Y; buttonArea.Height -= buttonAdjustment.Height; buttonArea.Width -= buttonAdjustment.Width; // Bug workaround: designer-made changes are not propagated to the incoming advancedBorderStyle here. // So correct for padding manually. Rectangle contentRect = GetContentBounds(graphics, cellStyle, rowIndex); buttonArea.X += contentRect.X; buttonArea.Y += contentRect.Y; buttonArea.Height = contentRect.Height; buttonArea.Width = contentRect.Width; ButtonRenderer.DrawButton(graphics, buttonArea, PushButtonState.Disabled); string buttonText = FormattedValue as string; if (buttonText != null) { TextRenderer.DrawText(graphics, buttonText, DataGridView.Font, buttonArea, SystemColors.GrayText); } } else { base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); } }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); if (DataGridView.SelectedCells.Count > 0 && DataGridView.SelectedCells[0] == this) { var bounds = cellBounds; bounds.Width--; bounds.Height--; ControlPaint.DrawBorder(graphics, bounds, SystemColors.ControlText, ButtonBorderStyle.Solid); } }
protected override void Paint( System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts ) { base.Paint( graphics, clipBounds, cellBounds, rowIndex, elementState, null, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts & ~DataGridViewPaintParts.ContentForeground & ~DataGridViewPaintParts.SelectionBackground ); if ( value != null ) { Image image = (Image) value; RectangleF destRect = new RectangleF( cellBounds.Left, cellBounds.Top, 48, 48 ); RectangleF srcRect = new RectangleF( -0.5f, -0.5f, image.Width, image.Height ); graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; graphics.DrawImage( image, destRect, srcRect, GraphicsUnit.Pixel ); } }
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) { if (!this.enabledValue) { if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background) { SolidBrush cellBackground = new SolidBrush(cellStyle.BackColor); graphics.FillRectangle(cellBackground, cellBounds); cellBackground.Dispose(); } if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border) { PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } Rectangle buttonArea = cellBounds; Rectangle buttonAdjustment = this.BorderWidths(advancedBorderStyle); buttonArea.X += buttonAdjustment.X; buttonArea.Y += buttonAdjustment.Y; buttonArea.Height -= buttonAdjustment.Height; buttonArea.Width -= buttonAdjustment.Width; ButtonRenderer.DrawButton(graphics, buttonArea, System.Windows.Forms.VisualStyles.PushButtonState.Disabled); if (this.FormattedValue is String) { TextRenderer.DrawText(graphics, (string)this.FormattedValue, this.DataGridView.Font, buttonArea, SystemColors.GrayText); } } else { base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); } }
protected override void Paint( Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { // Call the base class method to paint the default cell appearance. base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, null, null, errorText, cellStyle, advancedBorderStyle, paintParts); //境界線の内側に範囲を取得する Rectangle borderRect = this.BorderWidths(advancedBorderStyle); Rectangle innerRect = new Rectangle( cellBounds.Left + borderRect.Left, cellBounds.Top + borderRect.Top, cellBounds.Width - borderRect.Right, cellBounds.Height - borderRect.Bottom); Point middleCenter = new Point(); middleCenter.X = innerRect.X + innerRect.Width / 2; middleCenter.Y = innerRect.Y + innerRect.Height / 2; Int32 rebirthCount = (value == null) ? 0 : (Int32)value; for (Int32 i = 0; i < REBIRTH_COUNT; ++i) { bool isRebirth = (i < rebirthCount); Image img = ResourceUtil.GetPictureRebirth(isRebirth); Int32 halfImgWidth = img.Width / 2; Int32 halfImgHeight = img.Height / 2; Rectangle imgRect = new Rectangle( middleCenter.X + img.Width * i - halfImgWidth * REBIRTH_COUNT, middleCenter.Y - halfImgHeight, img.Width + 0, img.Height + 0); graphics.DrawImage(img, imgRect); } }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { // Prepaint DataGridViewPaintParts pre = DataGridViewPaintParts.Background | DataGridViewPaintParts.SelectionBackground; pre = pre & paintParts; base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, pre); // Paint content if ((paintParts & DataGridViewPaintParts.ContentForeground) == DataGridViewPaintParts.ContentForeground) { Color color = Selected ? cellStyle.SelectionForeColor : cellStyle.ForeColor; TextFormatFlags flags = TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter | TextFormatFlags.TextBoxControl; Rectangle contentbounds = cellBounds; contentbounds.Height -= 2; contentbounds.Width -= 2; if (formattedValue != null) { TextRenderer.DrawText(graphics, formattedValue.ToString(), cellStyle.Font, contentbounds, color, flags); } Point loc = new Point(cellBounds.Right - 14, cellBounds.Y + ((cellBounds.Height - 4) / 2)); if (sortGlyphDirection == SortOrder.Ascending) { using (Pen p = new Pen(color)) { graphics.DrawLine(p, loc.X + 4, loc.Y + 1, loc.X + 4, loc.Y + 2); graphics.DrawLine(p, loc.X + 3, loc.Y + 2, loc.X + 5, loc.Y + 2); graphics.DrawLine(p, loc.X + 2, loc.Y + 3, loc.X + 6, loc.Y + 3); graphics.DrawLine(p, loc.X + 1, loc.Y + 4, loc.X + 7, loc.Y + 4); graphics.DrawLine(p, loc.X + 0, loc.Y + 5, loc.X + 8, loc.Y + 5); } } else if (sortGlyphDirection == SortOrder.Descending) { using (Pen p = new Pen(color)) { graphics.DrawLine(p, loc.X + 4, loc.Y + 5, loc.X + 4, loc.Y + 4); graphics.DrawLine(p, loc.X + 3, loc.Y + 4, loc.X + 5, loc.Y + 4); graphics.DrawLine(p, loc.X + 2, loc.Y + 3, loc.X + 6, loc.Y + 3); graphics.DrawLine(p, loc.X + 1, loc.Y + 2, loc.X + 7, loc.Y + 2); graphics.DrawLine(p, loc.X + 0, loc.Y + 1, loc.X + 8, loc.Y + 1); } } } // Postpaint DataGridViewPaintParts post = DataGridViewPaintParts.Border; if (this is DataGridViewTopLeftHeaderCell) { post |= DataGridViewPaintParts.ErrorIcon; } post = post & paintParts; base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, post); }
protected override void Paint(sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts) { if (!object.ReferenceEquals(cachedGraphicsKey, graphics) || cachedGraphics == null) { cachedGraphicsKey = graphics; cachedGraphics = new Graphics(Handler.Generator, new GraphicsHandler(graphics, shouldDisposeGraphics: false)); } if (Handler.Widget.PaintHandler != null) { var b = graphics.ClipBounds; graphics.SetClip(clipBounds); Handler.Widget.PaintHandler(new DrawableCellPaintArgs { Graphics = cachedGraphics, CellBounds = new RectangleF(cellBounds.ToEto()), Item = value, CellState = cellState.ToEto(), }); graphics.SetClip(b); // restore } }
protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, System.Windows.Forms.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, System.Windows.Forms.DataGridViewCellStyle cellStyle, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle, System.Windows.Forms.DataGridViewPaintParts paintParts) { Single progressVal; try { progressVal = Conversions.ToSingle(value); } catch (Exception ex) { Console.WriteLine(ex.Message); progressVal = 0; } float percentage = (float)(progressVal / 100); Brush backBrush = new SolidBrush(cellStyle.BackColor); Brush foreBrush = new SolidBrush(cellStyle.ForeColor); // Call the base Class method to paint the default cell appearance. base.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); if (percentage > 0.0) { if (percentage > 1) { percentage = 1; } // Draw the progress bar and the text Rectangle rect = new Rectangle(cellBounds.X + 1, cellBounds.Y + 1, Convert.ToInt32((percentage * cellBounds.Width - 3)), cellBounds.Height - 3); DrawingMethods.DrawGradient(g, rect, Color.FromArgb(205, 255, 205), Color.FromArgb(10, 209, 48), 90F, false, Color.White, 0); g.DrawRectangle(new Pen(Color.FromArgb(28, 220, 56)), rect.X, rect.Y, rect.Width - 1, rect.Height - 1); //g.FillRectangle(New SolidBrush(Color.FromArgb(163, 189, 242)), cellBounds.X + 2, cellBounds.Y + 2, Convert.ToInt32((percentage * cellBounds.Width - 4)), cellBounds.Height - 4) g.DrawString(progressVal.ToString() + "%", cellStyle.Font, foreBrush, cellBounds.X + 6, cellBounds.Y + 4); } else { //draw the text if ((this.DataGridView.CurrentCell != null) && this.DataGridView.CurrentCell.RowIndex == rowIndex) { g.DrawString(progressVal.ToString() + "%", cellStyle.Font, new SolidBrush(cellStyle.SelectionForeColor), cellBounds.X + 6, cellBounds.Y + 4); } else { g.DrawString(progressVal.ToString() + "%", cellStyle.Font, foreBrush, cellBounds.X + 6, cellBounds.Y + 4); } } }
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts) { Handler.Paint(graphics, clipBounds, ref cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, ref paintParts); var val = value as object[]; var img = val[0] as sd.Image; if (img != null) { var container = graphics.BeginContainer(); graphics.SetClip(cellBounds); graphics.InterpolationMode = InterpolationMode; graphics.DrawImage(img, new sd.Rectangle(cellBounds.X + IconPadding, cellBounds.Y + (cellBounds.Height - Math.Min(img.Height, cellBounds.Height)) / 2, IconSize, IconSize)); graphics.EndContainer(container); cellBounds.X += IconSize + IconPadding * 2; cellBounds.Width -= IconSize + IconPadding * 2; } base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); }
/// <summary> /// Overrides Paint /// </summary> /// <param name="graphics"></param> /// <param name="clipBounds"></param> /// <param name="cellBounds"></param> /// <param name="rowIndex"></param> /// <param name="cellState"></param> /// <param name="value"></param> /// <param name="formattedValue"></param> /// <param name="errorText"></param> /// <param name="cellStyle"></param> /// <param name="advancedBorderStyle"></param> /// <param name="paintParts"></param> protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, System.Windows.Forms.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, System.Windows.Forms.DataGridViewCellStyle cellStyle, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle, System.Windows.Forms.DataGridViewPaintParts paintParts) { //Draw the bar int barWidth; if ((double)value >= 1.0) { barWidth = (int)(cellBounds.Width - 10); } else { barWidth = (int)((cellBounds.Width - 10) * (double)value); } if ((double)value > 0 && barWidth > 0) { Rectangle r = new Rectangle(cellBounds.X + 3, cellBounds.Y + 3, barWidth, cellBounds.Height - 8); using (LinearGradientBrush linearBrush = new LinearGradientBrush(r, KryptonManager.CurrentGlobalPalette.GetBackColor1(PaletteBackStyle.GridHeaderColumnList, PaletteState.Normal), KryptonManager.CurrentGlobalPalette.GetBackColor2(PaletteBackStyle.GridHeaderColumnList, PaletteState.Normal), LinearGradientMode.Vertical)) { graphics.FillRectangle(linearBrush, r); } using (Pen pen = new Pen(KryptonManager.CurrentGlobalPalette.GetBorderColor1(PaletteBorderStyle.GridHeaderColumnList, PaletteState.Normal))) { graphics.DrawRectangle(pen, r); } //TODO : implement customization like conditional formatting //using (LinearGradientBrush linearBrush = new LinearGradientBrush(r, Color.FromArgb(255, 140, 197, 66), Color.FromArgb(255, 247, 251, 242), LinearGradientMode.Horizontal)) //{ // graphics.FillRectangle(linearBrush, r); //} //using (Pen pen = new Pen(Color.FromArgb(255, 140, 197, 66))) //{ // graphics.DrawRectangle(pen, r); //} } base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, DataGridViewPaintParts.None | DataGridViewPaintParts.ContentForeground); }
protected override void PaintBorder(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle bounds, System.Windows.Forms.DataGridViewCellStyle cellStyle, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle) { base.PaintBorder(graphics, clipBounds, bounds, cellStyle, advancedBorderStyle); }
// 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 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 != 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 && DataGridViewCell.PaintBackground(paintParts)) { if (this.DataGridView.ApplyVisualStylesToHeaderCells) { // XP Theming int state = (int)HeaderItemState.Normal; if (this.ButtonState != ButtonState.Normal) { Debug.Assert(this.ButtonState == ButtonState.Pushed); state = (int)HeaderItemState.Pressed; } else if (this.DataGridView.MouseEnteredCellAddress.Y == rowIndex && this.DataGridView.MouseEnteredCellAddress.X == this.ColumnIndex) { state = (int)HeaderItemState.Hot; } valBounds.Inflate(16, 16); DataGridViewTopLeftHeaderCellRenderer.DrawHeader(graphics, valBounds, state); valBounds.Inflate(-16, -16); } else { SolidBrush br = this.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && cellSelected) ? cellStyle.SelectionBackColor : cellStyle.BackColor); if (br.Color.A == 255) { graphics.FillRectangle(br, valBounds); } } } if (paint && DataGridViewCell.PaintBorder(paintParts)) { PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } 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; 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 (this.DataGridView.ApplyVisualStylesToHeaderCells) { textColor = DataGridViewTopLeftHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor); } else { textColor = cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor; } TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(this.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode); if (paint) { if (DataGridViewCell.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 (this.DataGridView.ShowCellErrors && paint && DataGridViewCell.PaintErrorIcon(paintParts)) { PaintErrorIcon(graphics, cellStyle, rowIndex, cellBounds, errorBounds, errorText); } return(resultBounds); }
protected override void Paint(sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts) { // save graphics state to prevent artifacts in other paint operations in the grid var state = graphics.Save(); if (!ReferenceEquals(cachedGraphicsKey, graphics) || cachedGraphics == null) { cachedGraphicsKey = graphics; cachedGraphics = new Graphics(new GraphicsHandler(graphics, dispose: false)); } else { ((GraphicsHandler)cachedGraphics.Handler).SetInitialState(); } graphics.PixelOffsetMode = sd.Drawing2D.PixelOffsetMode.Half; graphics.SetClip(cellBounds); var color = new sd.SolidBrush(cellState.HasFlag(swf.DataGridViewElementStates.Selected) ? cellStyle.SelectionBackColor : cellStyle.BackColor); graphics.FillRectangle(color, cellBounds); var args = new CellPaintEventArgs(cachedGraphics, cellBounds.ToEto(), cellState.ToEto(), value); Handler.Callback.OnPaint(Handler.Widget, args); graphics.ResetClip(); graphics.Restore(state); }
protected override void Paint(sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts) { // save graphics state to prevent artifacts in other paint operations in the grid var state = graphics.Save(); if (!object.ReferenceEquals(cachedGraphicsKey, graphics) || cachedGraphics == null) { cachedGraphicsKey = graphics; cachedGraphics = new Graphics(new GraphicsHandler(graphics, dispose: false)); } else { ((GraphicsHandler)cachedGraphics.Handler).SetInitialState(); } graphics.SetClip(cellBounds); #pragma warning disable 618 var args = new DrawableCellPaintEventArgs(cachedGraphics, cellBounds.ToEto(), cellState.ToEto(), value); Handler.Callback.OnPaint(Handler.Widget, args); #pragma warning restore 618 graphics.ResetClip(); graphics.Restore(state); }
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, System.Windows.Forms.DataGridViewElementStates elementState, object value, object formattedValue, string errorText, System.Windows.Forms.DataGridViewCellStyle cellStyle, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle, System.Windows.Forms.DataGridViewPaintParts paintParts) { try { object o; o = value; base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, "", "", errorText, cellStyle, advancedBorderStyle, paintParts); //load Icons from resources //arrows ImageList GridIcons = new ImageList(); GridIcons.ColorDepth = ColorDepth.Depth32Bit; string iconOkName; string iconFailName; string iconNoneName; //Icon icon; //Bitmap icon; //Ok iconOkName = "AC.ExtendedRenderer.Toolkit.StdControls.Images.Up.png"; //Fail iconFailName = "AC.ExtendedRenderer.Toolkit.StdControls.Images.Down.png"; //None iconNoneName = "AC.ExtendedRenderer.Toolkit.StdControls.Images.Question.png"; int ngXlocation = (cellBounds.Width - 16); int ngYlocation = (cellBounds.Height - 16); if (ngXlocation < 0) { ngXlocation = 0; } if (ngYlocation < 0) { ngYlocation = 0; } ngXlocation = ngXlocation / 2; ngYlocation = ngYlocation / 2; Rectangle ng = new Rectangle(cellBounds.X + ngXlocation, cellBounds.Y + ngYlocation, 16, 16); if ((((o) != null))) { Single c; c = Conversions.ToSingle(o); //Debug //MessageBox.Show(c) Brush backBrush = new SolidBrush(cellStyle.BackColor); if (elementState == DataGridViewElementStates.Selected) { backBrush = new SolidBrush(Color.Gold); } //erase background if (c == 1) { //graphics.FillRectangle(backBrush, cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height) using (Bitmap tmpBitmap = new Bitmap(this.GetType().Assembly.GetManifestResourceStream(iconOkName))) { tmpBitmap.MakeTransparent(); graphics.DrawImage(tmpBitmap, ng); } } else if (c == 0) { //graphics.FillRectangle(backBrush, cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height) using (Bitmap tmpBitmap = new Bitmap(this.GetType().Assembly.GetManifestResourceStream(iconFailName))) { tmpBitmap.MakeTransparent(); graphics.DrawImage(tmpBitmap, ng); } } else { //graphics.FillRectangle(backBrush, cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height) using (Bitmap tmpBitmap = new Bitmap(this.GetType().Assembly.GetManifestResourceStream(iconNoneName))) { tmpBitmap.MakeTransparent(); graphics.DrawImage(tmpBitmap, ng); } } } PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } catch { // empty catch //MessageBox.Show(ex.Message) base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } }
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, System.Windows.Forms.DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, System.Windows.Forms.DataGridViewCellStyle cellStyle, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle, System.Windows.Forms.DataGridViewPaintParts paintParts) { string spaces = new string(' ', 2); l = new Point(cellBounds.Width - 18, 5); base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, spaces + value.ToString().Trim(), spaces + formattedValue.ToString().Trim(), errorText, cellStyle, advancedBorderStyle, paintParts); CheckBoxRenderer.DrawCheckBox(graphics, new Point(cellBounds.X + l.X, l.Y), isChecked ? System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal : System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal); }
/// <summary> /// Overrides Paint /// </summary> /// <param name="graphics"></param> /// <param name="clipBounds"></param> /// <param name="cellBounds"></param> /// <param name="rowIndex"></param> /// <param name="cellState"></param> /// <param name="value"></param> /// <param name="formattedValue"></param> /// <param name="errorText"></param> /// <param name="cellStyle"></param> /// <param name="advancedBorderStyle"></param> /// <param name="paintParts"></param> protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, System.Windows.Forms.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, System.Windows.Forms.DataGridViewCellStyle cellStyle, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle, System.Windows.Forms.DataGridViewPaintParts paintParts) { //Double p = 0; //Single percentage = 0f; //if (value != null && Double.TryParse((string)value, out p)) //{ //p = Convert.ToDouble(value); //percentage = (Convert.ToSingle(value) / 100f); //formattedValue = value + "%"; //} //Draw the bar int barWidth = (int)((cellBounds.Width - 10) * (double)value); if ((double)value > 0 && barWidth > 0) { Rectangle r = new Rectangle(cellBounds.X + 5, cellBounds.Y + 3, barWidth, cellBounds.Height - 8); using (LinearGradientBrush linearBrush = new LinearGradientBrush(r, KryptonManager.CurrentGlobalPalette.GetBackColor1(PaletteBackStyle.GridHeaderColumnList, PaletteState.Normal), KryptonManager.CurrentGlobalPalette.GetBackColor2(PaletteBackStyle.GridHeaderColumnList, PaletteState.Normal), LinearGradientMode.Vertical)) { graphics.FillRectangle(linearBrush, r); } using (Pen pen = new Pen(KryptonManager.CurrentGlobalPalette.GetBackColor2(PaletteBackStyle.GridHeaderColumnList, PaletteState.Normal))) { graphics.DrawRectangle(pen, r); // graphics.DrawRectangle(Pens.DimGray, r); } } base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, DataGridViewPaintParts.None | DataGridViewPaintParts.ContentForeground); }
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, System.Windows.Forms.DataGridViewElementStates elementState, object value, object formattedValue, string errorText, System.Windows.Forms.DataGridViewCellStyle cellStyle, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle, System.Windows.Forms.DataGridViewPaintParts paintParts) { try { object o; o = value; base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, "", "", errorText, cellStyle, advancedBorderStyle, paintParts); //load Icons from resources //arrows ImageList GridIcons = new ImageList(); //System.IO.Stream strm; string iconName; Icon icon; //UP iconName = "AC.ExtendedRenderer.Toolkit.StdControls.Images.Up.ico"; icon = new Icon(this.GetType().Assembly.GetManifestResourceStream(iconName)); GridIcons.Images.Add(icon.ToBitmap()); //Down iconName = "AC.ExtendedRenderer.Toolkit.StdControls.Images.Down.ico"; icon = new Icon(this.GetType().Assembly.GetManifestResourceStream(iconName)); GridIcons.Images.Add(icon.ToBitmap()); //Equal iconName = "AC.ExtendedRenderer.Toolkit.StdControls.Images.Eq.ico"; icon = new Icon(this.GetType().Assembly.GetManifestResourceStream(iconName)); GridIcons.Images.Add(icon.ToBitmap()); //Na //iconName = "AC.Utils.Na.ico" iconName = "AC.ExtendedRenderer.Toolkit.StdControls.Images.Na2.ico"; icon = new Icon(this.GetType().Assembly.GetManifestResourceStream(iconName)); GridIcons.Images.Add(icon.ToBitmap()); int ngXlocation = (cellBounds.Width - 16); int ngYlocation = (cellBounds.Height - 16); if (ngXlocation < 0) { ngXlocation = 0; } if (ngYlocation < 0) { ngYlocation = 0; } ngXlocation = ngXlocation / 2; ngYlocation = ngYlocation / 2; Rectangle ng = new Rectangle(cellBounds.X + ngXlocation, cellBounds.Y + ngYlocation, 16, 16); if ((((o) != null))) { Single c; c = Conversions.ToSingle(o); //Debug //MessageBox.Show(c) Brush backBrush = new SolidBrush(cellStyle.BackColor); if (elementState == DataGridViewElementStates.Selected) { backBrush = new SolidBrush(Color.Gold); } //erase background if (c == 1) { //graphics.FillRectangle(backBrush, cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height) graphics.DrawImage(GridIcons.Images[0], ng); } else if (c == -1) { //graphics.FillRectangle(backBrush, cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height) graphics.DrawImage(GridIcons.Images[1], ng); } else if (c == 0) { //graphics.FillRectangle(backBrush, cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height) graphics.DrawImage(GridIcons.Images[2], ng); } else if (c == 2) { //graphics.FillRectangle(backBrush, cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height) graphics.DrawImage(GridIcons.Images[3], ng); } else { //graphics.FillRectangle(backBrush, cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height) } } PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } catch { // empty catch //MessageBox.Show(ex.Message) base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } }
protected override void Paint(sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts) { if (!object.ReferenceEquals(cachedGraphicsKey, graphics) || cachedGraphics == null) { cachedGraphicsKey = graphics; cachedGraphics = new Graphics(new GraphicsHandler(graphics, shouldDisposeGraphics: false)); } graphics.SetClip(cellBounds); var args = new DrawableCellPaintEventArgs(cachedGraphics, cellBounds.ToEto(), cellState.ToEto(), value); Handler.Callback.OnPaint(Handler.Widget, args); graphics.ResetClip(); }
// 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 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 != null); if (paint && DataGridViewCell.PaintBorder(paintParts)) { PaintBorder(g, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } Rectangle resultBounds = Rectangle.Empty; Rectangle borderWidths = BorderWidths(advancedBorderStyle); Rectangle valBounds = cellBounds; valBounds.Offset(borderWidths.X, borderWidths.Y); valBounds.Width -= borderWidths.Right; valBounds.Height -= borderWidths.Bottom; Point ptCurrentCell = this.DataGridView.CurrentCellAddress; bool cellCurrent = ptCurrentCell.X == this.ColumnIndex && ptCurrentCell.Y == rowIndex; bool cellSelected = (cellState & DataGridViewElementStates.Selected) != 0; SolidBrush br = this.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && cellSelected) ? cellStyle.SelectionBackColor : cellStyle.BackColor); if (paint && DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255) { g.FillRectangle(br, 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; string formattedValueStr = formattedValue as string; if (formattedValueStr != null && (paint || computeContentBounds)) { // Font independent margins valBounds.Offset(DATAGRIDVIEWLINKCELL_horizontalTextMarginLeft, DATAGRIDVIEWLINKCELL_verticalTextMarginTop); valBounds.Width -= DATAGRIDVIEWLINKCELL_horizontalTextMarginLeft + DATAGRIDVIEWLINKCELL_horizontalTextMarginRight; valBounds.Height -= DATAGRIDVIEWLINKCELL_verticalTextMarginTop + DATAGRIDVIEWLINKCELL_verticalTextMarginBottom; if ((cellStyle.Alignment & anyBottom) != 0) { valBounds.Height -= DATAGRIDVIEWLINKCELL_verticalTextMarginBottom; } Font linkFont = null; Font hoverFont = null; LinkUtilities.EnsureLinkFonts(cellStyle.Font, this.LinkBehavior, ref linkFont, ref hoverFont); TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(this.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode); // paint the focus rectangle around the link if (paint) { if (valBounds.Width > 0 && valBounds.Height > 0) { if (cellCurrent && this.DataGridView.ShowFocusCues && this.DataGridView.Focused && DataGridViewCell.PaintFocus(paintParts)) { Rectangle focusBounds = DataGridViewUtilities.GetTextBounds(valBounds, formattedValueStr, flags, cellStyle, this.LinkState == LinkState.Hover ? hoverFont : linkFont); if ((cellStyle.Alignment & anyLeft) != 0) { focusBounds.X--; focusBounds.Width++; } else if ((cellStyle.Alignment & anyRight) != 0) { focusBounds.X++; focusBounds.Width++; } focusBounds.Height += 2; ControlPaint.DrawFocusRectangle(g, focusBounds, Color.Empty, br.Color); } Color linkColor; if ((this.LinkState & LinkState.Active) == LinkState.Active) { linkColor = this.ActiveLinkColor; } else if (this.LinkVisited) { linkColor = this.VisitedLinkColor; } else { linkColor = this.LinkColor; } if (DataGridViewCell.PaintContentForeground(paintParts)) { if ((flags & TextFormatFlags.SingleLine) != 0) { flags |= TextFormatFlags.EndEllipsis; } TextRenderer.DrawText(g, formattedValueStr, this.LinkState == LinkState.Hover ? hoverFont : linkFont, valBounds, linkColor, flags); } } else if (cellCurrent && this.DataGridView.ShowFocusCues && this.DataGridView.Focused && DataGridViewCell.PaintFocus(paintParts) && errorBounds.Width > 0 && errorBounds.Height > 0) { // Draw focus rectangle ControlPaint.DrawFocusRectangle(g, errorBounds, Color.Empty, br.Color); } } else { Debug.Assert(computeContentBounds); resultBounds = DataGridViewUtilities.GetTextBounds(valBounds, formattedValueStr, flags, cellStyle, this.LinkState == LinkState.Hover ? hoverFont : linkFont); } linkFont.Dispose(); hoverFont.Dispose(); } else if (paint || computeContentBounds) { if (cellCurrent && this.DataGridView.ShowFocusCues && this.DataGridView.Focused && DataGridViewCell.PaintFocus(paintParts) && paint && valBounds.Width > 0 && valBounds.Height > 0) { // Draw focus rectangle ControlPaint.DrawFocusRectangle(g, valBounds, Color.Empty, br.Color); } } else if (computeErrorIconBounds) { if (!string.IsNullOrEmpty(errorText)) { resultBounds = ComputeErrorIconBounds(errorBounds); } } if (this.DataGridView.ShowCellErrors && paint && DataGridViewCell.PaintErrorIcon(paintParts)) { PaintErrorIcon(g, cellStyle, rowIndex, cellBounds, errorBounds, errorText); } return(resultBounds); }
/// <summary> /// Paints the specified graphics. /// </summary> /// <param name="graphics">The graphics.</param> /// <param name="clipBounds">The clip bounds.</param> /// <param name="cellBounds">The cell bounds.</param> /// <param name="rowIndex">Index of the row.</param> /// <param name="cellState">State of the cell.</param> /// <param name="value">The value.</param> /// <param name="formattedValue">The formatted value.</param> /// <param name="errorText">The error text.</param> /// <param name="cellStyle">The cell style.</param> /// <param name="advancedBorderStyle">The advanced border style.</param> /// <param name="paintParts">The paint parts.</param> protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, System.Windows.Forms.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, System.Windows.Forms.DataGridViewCellStyle cellStyle, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle, System.Windows.Forms.DataGridViewPaintParts paintParts) { if (FormatParams != null) // null can happen when cell set to Formatting but no condition has been set ! { switch (FormatType) { case EnumConditionalFormatType.Bar: int barWidth; BarParams par = (BarParams)FormatParams; barWidth = (int)((cellBounds.Width - 10) * par.ProportionValue); Style.BackColor = this.DataGridView.DefaultCellStyle.BackColor; Style.ForeColor = this.DataGridView.DefaultCellStyle.ForeColor; if (barWidth > 0) //(double)value > 0 && { Rectangle r = new Rectangle(cellBounds.X + 3, cellBounds.Y + 3, barWidth, cellBounds.Height - 8); if (par.GradientFill) { using (LinearGradientBrush linearBrush = new LinearGradientBrush(r, par.BarColor, Color.White, LinearGradientMode.Horizontal)) //Color.FromArgb(255, 247, 251, 242) { graphics.FillRectangle(linearBrush, r); } } else { using (SolidBrush solidBrush = new SolidBrush(par.BarColor)) //Color.FromArgb(255, 247, 251, 242) { graphics.FillRectangle(solidBrush, r); } } using (Pen pen = new Pen(par.BarColor)) //Color.FromArgb(255, 140, 197, 66))) { graphics.DrawRectangle(pen, r); } } break; case EnumConditionalFormatType.TwoColorsRange: TwoColorsParams TWCpar = (TwoColorsParams)FormatParams; Style.BackColor = TWCpar.ValueColor; // if (ContrastTextColor) Style.ForeColor = ContrastColor(TWCpar.ValueColor); break; case EnumConditionalFormatType.ThreeColorsRange: ThreeColorsParams THCpar = (ThreeColorsParams)FormatParams; Style.BackColor = THCpar.ValueColor; Style.ForeColor = ContrastColor(THCpar.ValueColor); break; default: Style.BackColor = this.DataGridView.DefaultCellStyle.BackColor; Style.ForeColor = this.DataGridView.DefaultCellStyle.ForeColor; break; } } else { Style.BackColor = this.DataGridView.DefaultCellStyle.BackColor; Style.ForeColor = this.DataGridView.DefaultCellStyle.ForeColor; } base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, DataGridViewPaintParts.None | DataGridViewPaintParts.ContentForeground); }
//Paints the cell protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, System.Windows.Forms.DataGridViewElementStates elementState, object value, object formattedValue, string errorText, System.Windows.Forms.DataGridViewCellStyle cellStyle, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle, System.Windows.Forms.DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); if (m_Chart == null | cellBounds.Width != m_Width | cellBounds.Height != m_Height) { this.Value = GetTickChart(cellBounds); } m_CellBounds.Width = cellBounds.Width; m_CellBounds.Height = cellBounds.Height; m_CellBounds.X = cellBounds.X; m_CellBounds.Y = cellBounds.Y; m_Width = cellBounds.Width; m_Height = cellBounds.Height; }
protected void Paint(sd.Graphics graphics, sd.Rectangle clipBounds, ref sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, ref swf.DataGridViewPaintParts paintParts) { if (CellConfig != null) { CellConfig.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, ref paintParts); var offset = CellConfig.GetRowOffset(rowIndex); cellBounds.X += offset; cellBounds.Width -= offset; } }
protected override void Paint(sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates elementState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts) { formattedValue = ""; Handler.Paint(graphics, clipBounds, ref cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, ref paintParts); base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); float?progressVal; if (!(progressVal = value as float?).HasValue) { return; } float percentage = (float)progressVal; string progress = (int)(progressVal * 100f) + "%"; sd.Rectangle paintRect = new sd.Rectangle(cellBounds.X + 1, cellBounds.Y + 2, cellBounds.Width - 2, cellBounds.Height - 4); PaintBorder(graphics, clipBounds, paintRect, cellStyle, advancedBorderStyle); sd.Color bkColor; if (elementState == swf.DataGridViewElementStates.Selected) { bkColor = cellStyle.SelectionBackColor; } else { bkColor = cellStyle.BackColor; } using (sd.SolidBrush backBrush = new sd.SolidBrush(bkColor)) graphics.FillRectangle(backBrush, paintRect); if (swf.ProgressBarRenderer.IsSupported) { swf.ProgressBarRenderer.DrawHorizontalBar(graphics, paintRect); sd.Rectangle barBounds = new sd.Rectangle(paintRect.X + 2, paintRect.Y + 2, paintRect.Width - 4, paintRect.Height - 4); barBounds.Width = (int)Math.Round(barBounds.Width * percentage); swf.ProgressBarRenderer.DrawHorizontalChunks(graphics, barBounds); } else { sd.Rectangle barBounds = new sd.Rectangle(paintRect.X + 2, paintRect.Y + 2, paintRect.Width - 4, paintRect.Height - 3); barBounds.Width = (int)Math.Round(barBounds.Width * percentage); graphics.FillRectangle(sd.Brushes.LightGray, paintRect); graphics.DrawRectangle(sd.Pens.Black, paintRect); graphics.FillRectangle(new sd.SolidBrush(sd.Color.FromArgb(0, 216, 35)), barBounds); } swf.TextRenderer.DrawText(graphics, progress, cellStyle.Font, paintRect, cellStyle.ForeColor, swf.TextFormatFlags.HorizontalCenter | swf.TextFormatFlags.VerticalCenter); }
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, System.Windows.Forms.DataGridViewElementStates elementState, object value, object formattedValue, string errorText, System.Windows.Forms.DataGridViewCellStyle cellStyle, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle, System.Windows.Forms.DataGridViewPaintParts paintParts) { try { object o; o = value; if ((((o) != null))) { double c; c = Conversions.ToDouble(o); //Debug //MessageBox.Show(c) //erase background if (c < 0) { cellStyle.BackColor = Color.FromArgb(255, 200, 200); } else if (c == 0) { cellStyle.BackColor = Color.FromArgb(200, 200, 255); } else if (c > 0) { cellStyle.BackColor = Color.FromArgb(200, 255, 200); } } base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } catch { // empty catch //MessageBox.Show(ex.Message) base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } }
public override void Paint(GridColumnHandler column, sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, ref swf.DataGridViewPaintParts paintParts) { if (object.ReferenceEquals(column.Widget, this.Widget.Columns[0])) { // paint the background if (paintParts.HasFlag(swf.DataGridViewPaintParts.Background)) { sd.Brush brush; if (cellState.HasFlag(swf.DataGridViewElementStates.Selected)) { brush = new sd.SolidBrush(cellStyle.SelectionBackColor); } else { brush = new sd.SolidBrush(cellStyle.BackColor); } graphics.FillRectangle(brush, cellBounds); paintParts &= ~swf.DataGridViewPaintParts.Background; } var node = controller.GetNodeAtRow(rowIndex); var treeRect = cellBounds; treeRect.X += node.Level * INDENT_WIDTH; treeRect.Width = 16; if (ClassicStyle && ClassicGridLines) { // Draw grid lines - for classic style using (var linePen = new sd.Pen(sd.SystemBrushes.ControlDark, 1.0f)) { var lineRect = treeRect; lineRect.X += 7; lineRect.Width = 10; linePen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; var isFirstSibling = node.IsFirstNode; var isLastSibling = node.IsLastNode; if (node.Level == 0) { // the Root nodes display their lines differently if (isFirstSibling && isLastSibling) { // only node, both first and last. Just draw horizontal line graphics.DrawLine(linePen, lineRect.X, cellBounds.Top + cellBounds.Height / 2, lineRect.Right, cellBounds.Top + cellBounds.Height / 2); } else if (isLastSibling) { // last sibling doesn't draw the line extended below. Paint horizontal then vertical graphics.DrawLine(linePen, lineRect.X, cellBounds.Top + cellBounds.Height / 2, lineRect.Right, cellBounds.Top + cellBounds.Height / 2); graphics.DrawLine(linePen, lineRect.X, cellBounds.Top, lineRect.X, cellBounds.Top + cellBounds.Height / 2); } else if (isFirstSibling) { // first sibling doesn't draw the line extended above. Paint horizontal then vertical graphics.DrawLine(linePen, lineRect.X, cellBounds.Top + cellBounds.Height / 2, lineRect.Right, cellBounds.Top + cellBounds.Height / 2); graphics.DrawLine(linePen, lineRect.X, cellBounds.Top + cellBounds.Height / 2, lineRect.X, cellBounds.Bottom); } else { // normal drawing draws extended from top to bottom. Paint horizontal then vertical graphics.DrawLine(linePen, lineRect.X, cellBounds.Top + cellBounds.Height / 2, lineRect.Right, cellBounds.Top + cellBounds.Height / 2); graphics.DrawLine(linePen, lineRect.X, cellBounds.Top, lineRect.X, cellBounds.Bottom); } } else { if (isLastSibling) { // last sibling doesn't draw the line extended below. Paint horizontal then vertical graphics.DrawLine(linePen, lineRect.X, cellBounds.Top + cellBounds.Height / 2, lineRect.Right, cellBounds.Top + cellBounds.Height / 2); graphics.DrawLine(linePen, lineRect.X, cellBounds.Top, lineRect.X, cellBounds.Top + cellBounds.Height / 2); } else { // normal drawing draws extended from top to bottom. Paint horizontal then vertical graphics.DrawLine(linePen, lineRect.X, cellBounds.Top + cellBounds.Height / 2, lineRect.Right, cellBounds.Top + cellBounds.Height / 2); graphics.DrawLine(linePen, lineRect.X, cellBounds.Top, lineRect.X, cellBounds.Bottom); } // paint lines of previous levels to the root int horizontalStop = lineRect.X - INDENT_WIDTH; var previousNode = node.Parent; while (previousNode != null) { if (!previousNode.IsLastNode) { // paint vertical line graphics.DrawLine(linePen, horizontalStop, lineRect.Top, horizontalStop, lineRect.Bottom); } previousNode = previousNode.Parent; horizontalStop = horizontalStop - INDENT_WIDTH; } } } } if (node.Item.Expandable) { // draw open/close glyphs if (swf.Application.RenderWithVisualStyles) { EnsureGlyphRenderers(); if (controller.IsExpanded(rowIndex)) { openRenderer.DrawBackground(graphics, new sd.Rectangle(treeRect.X, treeRect.Y + (treeRect.Height / 2) - 8, 16, 16)); } else { closedRenderer.DrawBackground(graphics, new sd.Rectangle(treeRect.X, treeRect.Y + (treeRect.Height / 2) - 8, 16, 16)); } } else { // todo: draw +/- manually var glyphRect = treeRect; glyphRect.Width = glyphRect.Height = 8; glyphRect.X += 3; glyphRect.Y += (treeRect.Height - glyphRect.Height) / 2; graphics.FillRectangle(sd.SystemBrushes.Window, glyphRect); graphics.DrawRectangle(sd.SystemPens.ControlDark, glyphRect); glyphRect.Inflate(-2, -2); if (!controller.IsExpanded(rowIndex)) { var midx = glyphRect.X + glyphRect.Width / 2; graphics.DrawLine(sd.SystemPens.ControlDarkDark, midx, glyphRect.Top, midx, glyphRect.Bottom); } var midy = glyphRect.Y + glyphRect.Height / 2; graphics.DrawLine(sd.SystemPens.ControlDarkDark, glyphRect.Left, midy, glyphRect.Right, midy); } } } }
protected override void Paint(sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts) { Handler.Paint(graphics, clipBounds, ref cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, ref paintParts); var val = value as object[]; var img = val[0] as sd.Image; if (img != null) { if (paintParts.HasFlag(swf.DataGridViewPaintParts.Background)) { using (var b = new sd.SolidBrush(cellState.HasFlag(swf.DataGridViewElementStates.Selected) ? cellStyle.SelectionBackColor : cellStyle.BackColor)) { graphics.FillRectangle(b, new sd.Rectangle(cellBounds.X, cellBounds.Y, IconSize + IconPadding * 2, cellBounds.Height)); } } var container = graphics.BeginContainer(); graphics.SetClip(cellBounds); if (paintParts.HasFlag(swf.DataGridViewPaintParts.Background)) { using (var background = new sd.SolidBrush(cellState.HasFlag(swf.DataGridViewElementStates.Selected) ? cellStyle.SelectionBackColor : cellStyle.BackColor)) graphics.FillRectangle(background, cellBounds); } graphics.InterpolationMode = InterpolationMode; graphics.DrawImage(img, new sd.Rectangle(cellBounds.X + IconPadding, cellBounds.Y + (cellBounds.Height - Math.Min(img.Height, cellBounds.Height)) / 2, IconSize, IconSize)); graphics.EndContainer(container); cellBounds.X += IconSize + IconPadding * 2; cellBounds.Width -= IconSize + IconPadding * 2; } base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); }
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, System.Windows.Forms.DataGridViewElementStates elementState, object value, object formattedValue, string errorText, System.Windows.Forms.DataGridViewCellStyle cellStyle, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle, System.Windows.Forms.DataGridViewPaintParts paintParts) { //Paint inactive cells base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, "", "", errorText, cellStyle, advancedBorderStyle, paintParts); try { if (rowIndex < 0) { return; } foreach (GoogleOgcs.EventColour.Palette ci in Forms.ColourMap.GoogleComboBox.Items) { if (ci.Name == this.Value.ToString()) { Brush boxBrush = new SolidBrush(ci.RgbValue); Brush textBrush = SystemBrushes.WindowText; Extensions.ColourCombobox.DrawComboboxItemColour(true, boxBrush, textBrush, this.Value.ToString(), graphics, cellBounds); break; } } } catch (System.Exception ex) { OGCSexception.Analyse("GoogleColourComboboxCell.Paint()", ex); } }
public virtual void Paint(GridColumnHandler column, System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, ref swf.DataGridViewPaintParts paintParts) { }
protected override void Paint(sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates elementState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts) { graphics.InterpolationMode = InterpolationMode; Handler.Paint(graphics, clipBounds, ref cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, ref paintParts); base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); }
protected internal virtual void PaintCells(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, int rowIndex, DataGridViewElementStates rowState, bool isFirstDisplayedRow, bool isLastVisibleRow, DataGridViewPaintParts paintParts) { List <DataGridViewColumn> sortedColumns = DataGridView.Columns.ColumnDisplayIndexSortedArrayList; Rectangle bounds = rowBounds; // If row headers are visible, adjust our starting point if (DataGridView.RowHeadersVisible) { bounds.X += DataGridView.RowHeadersWidth; bounds.Width -= DataGridView.RowHeadersWidth; } for (int i = DataGridView.first_col_index; i < sortedColumns.Count; i++) { DataGridViewColumn col = sortedColumns[i]; if (!col.Visible) { continue; } if (!col.Displayed) { break; } bounds.Width = col.Width; DataGridViewCell cell = Cells[col.Index]; if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background) { graphics.FillRectangle(Brushes.White, bounds); } DataGridViewCellStyle style; if (cell.RowIndex == -1) { style = DefaultCellStyle; } else { style = cell.InheritedStyle; } object value; object formattedValue; string errorText; DataGridViewElementStates cellState; if (cell.RowIndex == -1) { // TODO: Look up value if databound. value = null; formattedValue = null; errorText = null; cellState = cell.State; } else { value = cell.Value; formattedValue = cell.FormattedValue; errorText = cell.ErrorText; cellState = cell.InheritedState; } DataGridViewAdvancedBorderStyle intermediateBorderStyle = (DataGridViewAdvancedBorderStyle)((ICloneable)DataGridView.AdvancedCellBorderStyle).Clone(); DataGridViewAdvancedBorderStyle borderStyle = cell.AdjustCellBorderStyle(DataGridView.AdvancedCellBorderStyle, intermediateBorderStyle, true, true, cell.ColumnIndex == 0, cell.RowIndex == 0); DataGridView.OnCellFormattingInternal(new DataGridViewCellFormattingEventArgs(cell.ColumnIndex, cell.RowIndex, value, cell.FormattedValueType, style)); cell.PaintWork(graphics, clipBounds, bounds, rowIndex, cellState, style, borderStyle, paintParts); bounds.X += bounds.Width; } }
protected override void PaintBorder(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle) { if (ThemeEngine.Current.DataGridViewColumnHeaderCellDrawBorder(this, graphics, cellBounds)) { return; } Pen p = GetBorderPen(); if (ColumnIndex == -1) { graphics.DrawLine(p, cellBounds.Left, cellBounds.Top, cellBounds.Left, cellBounds.Bottom - 1); graphics.DrawLine(p, cellBounds.Right - 1, cellBounds.Top, cellBounds.Right - 1, cellBounds.Bottom - 1); graphics.DrawLine(p, cellBounds.Left, cellBounds.Bottom - 1, cellBounds.Right - 1, cellBounds.Bottom - 1); graphics.DrawLine(p, cellBounds.Left, cellBounds.Top, cellBounds.Right - 1, cellBounds.Top); } else { graphics.DrawLine(p, cellBounds.Left, cellBounds.Bottom - 1, cellBounds.Right - 1, cellBounds.Bottom - 1); graphics.DrawLine(p, cellBounds.Left, cellBounds.Top, cellBounds.Right - 1, cellBounds.Top); if (ColumnIndex == DataGridView.Columns.Count - 1 || ColumnIndex == -1) { graphics.DrawLine(p, cellBounds.Right - 1, cellBounds.Top, cellBounds.Right - 1, cellBounds.Bottom - 1); } else { graphics.DrawLine(p, cellBounds.Right - 1, cellBounds.Top + 3, cellBounds.Right - 1, cellBounds.Bottom - 3); } } }
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts) { Handler.Paint(graphics, clipBounds, ref cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, ref paintParts); base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); }
public void Paint(sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, ref swf.DataGridViewPaintParts paintParts) { if (GridHandler != null) { GridHandler.Paint(this, graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, ref paintParts); } }