1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
23 // Pedro MartÃnez Juliá <pedromj@gmail.com>
27 using System.ComponentModel;
30 namespace System.Windows.Forms {
32 public class DataGridViewCellPaintingEventArgs : HandledEventArgs {
34 private DataGridView dataGridView;
35 private Graphics graphics;
36 private Rectangle clipBounds;
37 private Rectangle cellBounds;
39 private int columnIndex;
40 private DataGridViewElementStates cellState;
41 private object cellValue;
42 private object formattedValue;
43 private string errorText;
44 private DataGridViewCellStyle cellStyle;
45 private DataGridViewAdvancedBorderStyle advancedBorderStyle;
46 private DataGridViewPaintParts paintParts;
48 public DataGridViewCellPaintingEventArgs (DataGridView dataGridView, Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, int columnIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) {
49 this.dataGridView = dataGridView;
50 this.graphics = graphics;
51 this.clipBounds = clipBounds;
52 this.cellBounds = cellBounds;
53 this.rowIndex = rowIndex;
54 this.columnIndex = columnIndex;
55 this.cellState = cellState;
56 this.cellValue = value;
57 this.formattedValue = formattedValue;
58 this.errorText = errorText;
59 this.cellStyle = cellStyle;
60 this.advancedBorderStyle = advancedBorderStyle;
61 this.paintParts = paintParts;
64 public DataGridViewAdvancedBorderStyle AdvancedBorderStyle {
65 get { return advancedBorderStyle; }
68 public Rectangle CellBounds {
69 get { return cellBounds; }
72 public DataGridViewCellStyle CellStyle {
73 get { return cellStyle; }
76 public Rectangle ClipBounds {
77 get { return clipBounds; }
80 public int ColumnIndex {
81 get { return columnIndex; }
84 public string ErrorText {
85 get { return errorText; }
88 public object FormattedValue {
89 get { return formattedValue; }
92 public Graphics Graphics {
93 get { return graphics; }
96 public DataGridViewPaintParts PaintParts {
97 get { return paintParts; }
100 public int RowIndex {
101 get { return rowIndex; }
104 public DataGridViewElementStates State {
105 get { return cellState; }
108 public object Value {
109 get { return cellValue; }
112 public void Paint (Rectangle clipBounds, DataGridViewPaintParts paintParts) {
113 if (rowIndex < -1 || rowIndex >= dataGridView.Rows.Count)
114 throw new InvalidOperationException("Invalid \"RowIndex.\"");
115 if (columnIndex < -1 || columnIndex >= dataGridView.Columns.Count)
116 throw new InvalidOperationException("Invalid \"ColumnIndex.\"");
118 DataGridViewCell cell;
120 if (rowIndex == -1 && columnIndex == -1)
121 cell = dataGridView.TopLeftHeaderCell;
122 else if (rowIndex == -1)
123 cell = dataGridView.Columns[columnIndex].HeaderCell;
124 else if (columnIndex == -1)
125 cell = dataGridView.Rows[rowIndex].HeaderCell;
127 cell = dataGridView.Rows[rowIndex].Cells[columnIndex];
129 cell.PaintInternal (graphics, clipBounds, cellBounds, rowIndex, cellState, Value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
132 public void PaintBackground (Rectangle clipBounds, bool cellsPaintSelectionBackground)
134 Paint (clipBounds, DataGridViewPaintParts.Background | DataGridViewPaintParts.Border);
137 [MonoInternalNote ("Needs row header cell edit pencil glyph")]
138 public void PaintContent (Rectangle clipBounds)
140 Paint (clipBounds, DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.ContentForeground);