System.Windows.Forms.Label.CalcImageRenderBounds C# (CSharp) Method

CalcImageRenderBounds() protected method

protected CalcImageRenderBounds ( Image image, Rectangle r, ContentAlignment align ) : Rectangle
image System.Drawing.Image
r System.Drawing.Rectangle
align ContentAlignment
return System.Drawing.Rectangle
		protected Rectangle CalcImageRenderBounds (Image image, Rectangle r, ContentAlignment align)
		{
			Rectangle rcImageClip = r;
			rcImageClip.Inflate (-2,-2);

			int X = r.X;
			int Y = r.Y;

			if (align == ContentAlignment.TopCenter ||
				align == ContentAlignment.MiddleCenter ||
				align == ContentAlignment.BottomCenter) {
				X += (r.Width - image.Width) / 2;
			} else if (align == ContentAlignment.TopRight ||
				align == ContentAlignment.MiddleRight||
				align == ContentAlignment.BottomRight) {
				X += (r.Width - image.Width);
			}

			if( align == ContentAlignment.BottomCenter ||
				align == ContentAlignment.BottomLeft ||
				align == ContentAlignment.BottomRight) {
				Y += r.Height - image.Height;
			} else if(align == ContentAlignment.MiddleCenter ||
					align == ContentAlignment.MiddleLeft ||
					align == ContentAlignment.MiddleRight) {
				Y += (r.Height - image.Height) / 2;
			}

			rcImageClip.X = X;
			rcImageClip.Y = Y;
			rcImageClip.Width = image.Width;
			rcImageClip.Height = image.Height;

			return rcImageClip;
		}