System.Windows.Forms.ThemeWin32Classic.CalculateButtonTextAndImageLayout C# (CSharp) Method

CalculateButtonTextAndImageLayout() public method

public CalculateButtonTextAndImageLayout ( Graphics g, ButtonBase button, Rectangle &textRectangle, Rectangle &imageRectangle ) : void
g System.Drawing.Graphics
button ButtonBase
textRectangle System.Drawing.Rectangle
imageRectangle System.Drawing.Rectangle
return void
		public override void CalculateButtonTextAndImageLayout (Graphics g, ButtonBase button, out Rectangle textRectangle, out Rectangle imageRectangle)
		{
			Image image = button.Image;
			string text = button.Text;
			Rectangle content_rect = button.PaddingClientRectangle;
			Size text_size = TextRenderer.MeasureTextInternal (g, text, button.Font, content_rect.Size, button.TextFormatFlags, button.UseCompatibleTextRendering);
			Size image_size = image == null ? Size.Empty : image.Size;

			textRectangle = Rectangle.Inflate (content_rect, -4, -4);
			imageRectangle = Rectangle.Empty;
			
			bool displayEllipsis = (button.TextFormatFlags & (TextFormatFlags.EndEllipsis | TextFormatFlags.PathEllipsis | TextFormatFlags.WordEllipsis)) != 0;

			switch (button.TextImageRelation) {
				case TextImageRelation.Overlay:
					// Overlay is easy, text always goes here

					// Image is dependent on ImageAlign
					if (image == null) {
						if (button.Pressed)
							textRectangle.Offset (1, 1);
						return;
					}
						
					int image_x = 0;
					int image_y = 0;
					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, image_y, image_width, image_height);
					break;
				case TextImageRelation.ImageAboveText:
					LayoutTextAboveOrBelowImage (textRectangle, false, text_size, image_size, button.TextAlign, button.ImageAlign, displayEllipsis, out textRectangle, out imageRectangle);
					break;
				case TextImageRelation.TextAboveImage:
					LayoutTextAboveOrBelowImage (textRectangle, true, text_size, image_size, button.TextAlign, button.ImageAlign, displayEllipsis, out textRectangle, out imageRectangle);
					break;
				case TextImageRelation.ImageBeforeText:
					LayoutTextBeforeOrAfterImage (textRectangle, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
					break;
				case TextImageRelation.TextBeforeImage:
					LayoutTextBeforeOrAfterImage (textRectangle, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
					break;
			}
			if (button.Pressed)
				textRectangle.Offset (1, 1);
		}
ThemeWin32Classic