class DataGridViewFavoriteCell : DataGridViewImageCell
{
public DataGridViewFavoriteCell()
{
//-Nastavim vychozi typ, ktery bude vracet metoda GetFormattedValue
ValueType = typeof(Bitmap);
}
protected override object GetFormattedValue(object value, int rowIndex, ref DataGridViewCellStyle cellStyle, System.ComponentModel.TypeConverter valueTypeConverter, System.ComponentModel.TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
{
//-Vratim vychozi obrazek, ktery mohu pouzivat v metode Paint
return Bitmaps.ci.FavoritePng;
}
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)
{
Image imgFavorites = null;
Point locFavorites = Point.Empty;
//-Moje vlastni metoda na vypocet souradnic na ktere zakreslit, vypocet velikosti obrazku a take zmenseni obrazku na pozadovanou velikost. Je vhodne nastavit nemennost sirky a vysky radku pokud je radku hodne, obrazek nacist jen jednou a pak jen pocitat jeho souradnice
Listing.CalculatePoint(cellBounds, Bitmaps.ci.FavoritePng, ImageFormats.Png, out locFavorites, out imgFavorites);
//-Vymaluji samotny obrazek. Je nutno nejdrive vymalovat pozadi, protoze jinak se pouzije to co ma aplikace pod nim
graphics.FillRectangle(Brushes.White, cellBounds);
graphics.DrawImage(imgFavorites, locFavorites);
Debug.Print(locFavorites.ToString());
//-Vymaluji okraje radku
base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
}
}