private static Rectangle OverlayObjectRect(ref Rectangle container, ref Size sizeOfObject, System.Drawing.ContentAlignment alignment)
{
int x, y;
switch (alignment)
{
case System.Drawing.ContentAlignment.TopLeft:
x = 4;
y = 4;
break;
case System.Drawing.ContentAlignment.TopCenter:
x = (container.Width - sizeOfObject.Width) / 2;
y = 4;
break;
case System.Drawing.ContentAlignment.TopRight:
x = container.Width - sizeOfObject.Width - 4;
y = 4;
break;
case System.Drawing.ContentAlignment.MiddleLeft:
x = 4;
y = (container.Height - sizeOfObject.Height) / 2;
break;
case System.Drawing.ContentAlignment.MiddleCenter:
x = (container.Width - sizeOfObject.Width) / 2;
y = (container.Height - sizeOfObject.Height) / 2;
break;
case System.Drawing.ContentAlignment.MiddleRight:
x = container.Width - sizeOfObject.Width - 4;
y = (container.Height - sizeOfObject.Height) / 2;
break;
case System.Drawing.ContentAlignment.BottomLeft:
x = 4;
y = container.Height - sizeOfObject.Height - 4;
break;
case System.Drawing.ContentAlignment.BottomCenter:
x = (container.Width - sizeOfObject.Width) / 2;
y = container.Height - sizeOfObject.Height - 4;
break;
case System.Drawing.ContentAlignment.BottomRight:
x = container.Width - sizeOfObject.Width - 4;
y = container.Height - sizeOfObject.Height - 4;
break;
default:
x = 4;
y = 4;
break;
}
return new Rectangle(x, y, sizeOfObject.Width, sizeOfObject.Height);
}