public override void CalculateCheckBoxTextAndImageLayout (ButtonBase button, Point p, out Rectangle glyphArea, out Rectangle textRectangle, out Rectangle imageRectangle)
{
int check_size = CheckSize;
if (button is CheckBox)
check_size = (button as CheckBox).Appearance == Appearance.Normal ? check_size : 0;
glyphArea = new Rectangle (button.Padding.Left, button.Padding.Top, check_size, check_size);
Rectangle content_rect = button.PaddingClientRectangle;
ContentAlignment align = ContentAlignment.TopLeft;
if (button is CheckBox)
align = (button as CheckBox).CheckAlign;
else if (button is RadioButton)
align = (button as RadioButton).CheckAlign;
switch (align) {
case ContentAlignment.BottomCenter:
glyphArea.Y += content_rect.Height - check_size - 2;
glyphArea.X += (content_rect.Width - check_size) / 2;
break;
case ContentAlignment.BottomLeft:
glyphArea.Y += content_rect.Height - check_size - 2;
content_rect.Width -= check_size;
content_rect.Offset (check_size, 0);
break;
case ContentAlignment.BottomRight:
glyphArea.Y += content_rect.Height - check_size - 2;
glyphArea.X += content_rect.Width - check_size;
content_rect.Width -= check_size;
break;
case ContentAlignment.MiddleCenter:
glyphArea.Y += (content_rect.Height - check_size) / 2;
glyphArea.X += (content_rect.Width - check_size) / 2;
break;
case ContentAlignment.MiddleLeft:
glyphArea.Y += (content_rect.Height - check_size) / 2;
content_rect.Width -= check_size;
content_rect.Offset (check_size, 0);
break;
case ContentAlignment.MiddleRight:
glyphArea.Y += (content_rect.Height - check_size) / 2;
glyphArea.X += content_rect.Width - check_size;
content_rect.Width -= check_size;
break;
case ContentAlignment.TopCenter:
glyphArea.X += (content_rect.Width - check_size) / 2;
break;
case ContentAlignment.TopLeft:
content_rect.Width -= check_size;
content_rect.Offset (check_size, 0);
break;
case ContentAlignment.TopRight:
glyphArea.X += content_rect.Width - check_size;
content_rect.Width -= check_size;
break;
}
Image image = button.Image;
string text = button.Text;
Size proposed = Size.Empty;
// Force wrapping if we aren't AutoSize and our text is too long
if (!button.AutoSize)
proposed.Width = button.PaddingClientRectangle.Width - glyphArea.Width - 2;
Size text_size = TextRenderer.MeasureTextInternal (text, button.Font, proposed, button.TextFormatFlags, button.UseCompatibleTextRendering);
// Text can't be bigger than the content rectangle
text_size.Height = Math.Min (text_size.Height, content_rect.Height);
text_size.Width = Math.Min (text_size.Width, content_rect.Width);
Size image_size = image == null ? Size.Empty : image.Size;
textRectangle = Rectangle.Empty;
imageRectangle = Rectangle.Empty;
switch (button.TextImageRelation) {
case TextImageRelation.Overlay:
// Text is centered vertically, and 2 pixels to the right
textRectangle.X = content_rect.Left + 2;
textRectangle.Y = button.PaddingClientRectangle.Top + ((content_rect.Height - text_size.Height) / 2) - 1;
textRectangle.Size = text_size;
// Image is dependent on ImageAlign
if (image == null)
return;
int image_x = button.PaddingClientRectangle.Left;
int image_y = button.PaddingClientRectangle.Top;
int image_height = image.Height;
int image_width = image.Width;
switch (button.ImageAlign) {
case System.Drawing.ContentAlignment.TopLeft:
image_x += 5;
image_y += 5;
break;
case System.Drawing.ContentAlignment.TopCenter:
image_x += (content_rect.Width - image_width) / 2;
image_y += 5;
break;
case System.Drawing.ContentAlignment.TopRight:
image_x += content_rect.Width - image_width - 5;
image_y += 5;
break;
case System.Drawing.ContentAlignment.MiddleLeft:
image_x += 5;
image_y += (content_rect.Height - image_height) / 2;
break;
case System.Drawing.ContentAlignment.MiddleCenter:
image_x += (content_rect.Width - image_width) / 2;
image_y += (content_rect.Height - image_height) / 2;
break;
case System.Drawing.ContentAlignment.MiddleRight:
image_x += content_rect.Width - image_width - 4;
image_y += (content_rect.Height - image_height) / 2;
break;
case System.Drawing.ContentAlignment.BottomLeft:
image_x += 5;
image_y += content_rect.Height - image_height - 4;
break;
case System.Drawing.ContentAlignment.BottomCenter:
image_x += (content_rect.Width - image_width) / 2;
image_y += content_rect.Height - image_height - 4;
break;
case System.Drawing.ContentAlignment.BottomRight:
image_x += content_rect.Width - image_width - 4;
image_y += content_rect.Height - image_height - 4;
break;
default:
image_x += 5;
image_y += 5;
break;
}
imageRectangle = new Rectangle (image_x + check_size, image_y, image_width, image_height);
break;
case TextImageRelation.ImageAboveText:
content_rect.Inflate (-4, -4);
LayoutTextAboveOrBelowImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, false, out textRectangle, out imageRectangle);
break;
case TextImageRelation.TextAboveImage:
content_rect.Inflate (-4, -4);
LayoutTextAboveOrBelowImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, false, out textRectangle, out imageRectangle);
break;
case TextImageRelation.ImageBeforeText:
content_rect.Inflate (-4, -4);
LayoutTextBeforeOrAfterImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
break;
case TextImageRelation.TextBeforeImage:
content_rect.Inflate (-4, -4);
LayoutTextBeforeOrAfterImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
break;
}
}