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

DrawPictureBox() public method

public DrawPictureBox ( Graphics dc, Rectangle clip, PictureBox pb ) : void
dc System.Drawing.Graphics
clip System.Drawing.Rectangle
pb PictureBox
return void
		public override void DrawPictureBox (Graphics dc, Rectangle clip, PictureBox pb) {
			Rectangle client = pb.ClientRectangle;

			client = new Rectangle (client.Left + pb.Padding.Left, client.Top + pb.Padding.Top, client.Width - pb.Padding.Horizontal, client.Height - pb.Padding.Vertical);

			// FIXME - instead of drawing the whole picturebox every time
			// intersect the clip rectangle with the drawn picture and only draw what's needed,
			// Also, we only need a background fill where no image goes
			if (pb.Image != null) {
				switch (pb.SizeMode) {
				case PictureBoxSizeMode.StretchImage:
					dc.DrawImage (pb.Image, client.Left, client.Top, client.Width, client.Height);
					break;

				case PictureBoxSizeMode.CenterImage:
					dc.DrawImage (pb.Image, (client.Width / 2) - (pb.Image.Width / 2), (client.Height / 2) - (pb.Image.Height / 2));
					break;

				case PictureBoxSizeMode.Zoom:
					Size image_size;
					
					if (((float)pb.Image.Width / (float)pb.Image.Height) >= ((float)client.Width / (float)client.Height))
						image_size = new Size (client.Width, (pb.Image.Height * client.Width) / pb.Image.Width);
					else
						image_size = new Size ((pb.Image.Width * client.Height) / pb.Image.Height, client.Height);

					dc.DrawImage (pb.Image, (client.Width / 2) - (image_size.Width / 2), (client.Height / 2) - (image_size.Height / 2), image_size.Width, image_size.Height);
					break;

				default:
					// Normal, AutoSize
					dc.DrawImage (pb.Image, client.Left, client.Top, pb.Image.Width, pb.Image.Height);
					break;
				}

				return;
			}
		}
ThemeWin32Classic