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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

centered Picture in Cell

Thread ID:





755 Aug 13,2002 08:42 AM UTC Aug 13,2002 09:08 AM UTC WinForms 1
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)
	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);


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon