We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

centered Picture in Cell

Thread ID:

Created:

Updated:

Platform:

Replies:

755 Aug 13,2002 08:42 AM UTC Aug 13,2002 09:08 AM UTC WinForms 1
loading
Tags: GridControl
Harald Egerth
Asked On August 13, 2002 08:42 AM UTC

Hi, My bitmap has the size 16x16, my column 24x20. I'd like to center/middle the picture. How can i center a Picture in a Gridcell ? hEgerth

Clay Burch [Syncfusion]
Replied On August 13, 2002 09:08 AM UTC

If you are using the ImageGridCell class from the ExcelSelectionMarker sample to display the bitmap, then you can change the OnDraw override to draw a centered bitmap. Here is some sample code.
protected override void OnDraw(System.Drawing.Graphics g, System.Drawing.Rectangle clientRectangle, int rowIndex, int colIndex, Syncfusion.Windows.Forms.Grid.GridStyleInfo style)
{
	if (clientRectangle.IsEmpty)
		return;
		
	if(style.Tag is Bitmap)
	{
		Size bmSize = ((Bitmap) style.Tag).Size;
		Rectangle targetRect = new Rectangle(clientRectangle.X, clientRectangle.Y, bmSize.Width, bmSize.Height);

		if( bmSize.Width < clientRectangle.Width )
			targetRect.X += (clientRectangle.Width - bmSize.Width) / 2;
		if( bmSize.Height < clientRectangle.Height )
			targetRect.Y += (clientRectangle.Height - bmSize.Height) / 2;

		g.DrawImage((Bitmap) style.Tag, targetRect);
	}
}

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;