0
我已經在datagridview中託管了一個自定義控件,讓我們說CustomControl(第三方控件),並且單元格只在進入編輯模式時才繪製。如果退出編輯模式,它不可見,所以我已經覆蓋了繪畫方法(見下文)。它在Windows 7中工作正常,但不在Windows XP中。 DrawToBitmap失敗。有任何想法嗎?DrawToBitmap不能在Windows XP上工作,但在Windows 7中是
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);
CustomControl customControl= (CustomControl)this.DataGridView.Rows[rowIndex].Cells[this.ColumnIndex].Value;
Bitmap img = new Bitmap(cellBounds.Width, cellBounds.Height);
// Resize propertyEditor control to cell bounds
propertyEditor.Height = cellBounds.Height;
propertyEditor.Width = cellBounds.Width;
// Sets the cell's backcolor according to the data grid view's color
customControl.BackColor = this.DataGridView.Rows[rowIndex].Cells[this.ColumnIndex].Style.BackColor;
// Finally paint the propertyEditor control
customControl.DrawToBitmap(img, new Rectangle(0, 0, customControl.Width, customControl.Height));
graphics.DrawImage(img, cellBounds.Location);
}