Draws Bitmap in a cell within a DataGridView
using System;
using System.Drawing;
using System.Windows.Forms;
class DataGridViewUtils
{
public static void DrawBitmapInCell(Bitmap bitmap, DataGridViewCellPaintingEventArgs e)
{
e.Graphics.DrawImage(
/*bitmap*/ bitmap,
/*x*/ (e.CellBounds.Left + ((e.CellBounds.Width - bitmap.Width) / 2)),
/*y*/ (e.CellBounds.Top + ((e.CellBounds.Height - bitmap.Height) / 2)),
/*width*/ bitmap.Width,
/*height*/ bitmap.Height);
}
}
Related examples in the same category