public void PaintHeader_InvalidRowIndex_ThrowsInvalidOperationException(int rowIndex) { using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { var dataGridView = new DataGridView(); dataGridView.Columns.Add("name", "text"); var e = new DataGridViewRowPostPaintEventArgs(dataGridView, graphics, Rectangle.Empty, Rectangle.Empty, rowIndex, DataGridViewElementStates.Displayed, null, new DataGridViewCellStyle(), false, false); Assert.Throws <InvalidOperationException>(() => e.PaintHeader(DataGridViewPaintParts.None)); Assert.Throws <InvalidOperationException>(() => e.PaintHeader(true)); } }
// Show variable type in row header and highlight AVGPR watches private void ReplaceDefaultRowHeaderBitmap(object sender, DataGridViewRowPostPaintEventArgs e) { if (e.RowIndex == _table.NewWatchRowIndex) { return; } var selectedWatch = VisualizerTable.GetRowWatchState(_table.Rows[e.RowIndex]); if (selectedWatch.IsAVGPR) { var highlightedRect = new Rectangle(e.RowBounds.Left + 3, e.RowBounds.Top + 3, _table.RowHeadersWidth - 6, e.RowBounds.Height - 6); e.Graphics.FillRectangle(_avgprColor, highlightedRect); } e.PaintHeader( DataGridViewPaintParts.Background | DataGridViewPaintParts.Border | DataGridViewPaintParts.Focus | DataGridViewPaintParts.SelectionBackground | DataGridViewPaintParts.ContentForeground ); if (!selectedWatch.IsEmpty) { var typeTextPos = new PointF((float)e.RowBounds.Left + 7, (float)e.RowBounds.Top + 4); e.Graphics.DrawString(selectedWatch.Type.ShortName(), _table.RowHeadersDefaultCellStyle.Font, new SolidBrush(_table.RowHeadersDefaultCellStyle.ForeColor), typeTextPos); } }
public void PaintHeader_ValidRowIndexBool_Success(bool paintSelectionBackground) { using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { var dataGridView = new DataGridView(); dataGridView.Columns.Add("name", "text"); var e = new DataGridViewRowPostPaintEventArgs(dataGridView, graphics, Rectangle.Empty, Rectangle.Empty, 0, DataGridViewElementStates.Displayed, null, new DataGridViewCellStyle(), false, false); e.PaintHeader(paintSelectionBackground); } }
/// <summary> /// Raised when the rows have been painted. /// </summary> /// <param name="e">The <see cref="DataGridViewRowPostPaintEventArgs"/>.</param> protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e) { // Draw the header manually to get rid of this ugly triangle. e.PaintHeader(DataGridViewPaintParts.Background); object headerValue = Rows[e.RowIndex].HeaderCell.Value; Rectangle headerRect = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, RowHeadersWidth, e.RowBounds.Height); TextRenderer.DrawText(e.Graphics, $"{headerValue}", RowHeadersDefaultCellStyle.Font, headerRect, RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter); }
private void ReplaceDefaultRowHeaderBitmap(object sender, DataGridViewRowPostPaintEventArgs e) { if (_table.Rows[e.RowIndex].HeaderCell.Value == null) { return; } e.PaintHeader( DataGridViewPaintParts.Background | DataGridViewPaintParts.Border | DataGridViewPaintParts.Focus | DataGridViewPaintParts.SelectionBackground | DataGridViewPaintParts.ContentForeground ); var typeTextPos = new PointF((float)e.RowBounds.Left + 7, (float)e.RowBounds.Top + 4); e.Graphics.DrawString(_table.Rows[e.RowIndex].HeaderCell.Value.ToString(), _table.RowHeadersDefaultCellStyle.Font, new SolidBrush(_table.RowHeadersDefaultCellStyle.ForeColor), typeTextPos); }
private void wordsAudioGrid_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { e.PaintHeader(DataGridViewPaintParts.All & ~DataGridViewPaintParts.ContentBackground); }