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.
Unfortunately, activation email could not send to your email. Please try again.

centered Picture in Cell

Thread ID:





755 Aug 13,2002 04:42 AM Aug 13,2002 05:08 AM Windows Forms 1
Tags: GridControl
Harald Egerth
Asked On August 13, 2002 04:42 AM

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 05:08 AM

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.

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.