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

DrawProgressBar() public method

public DrawProgressBar ( Graphics dc, Rectangle clip_rect, System.Windows.Forms.ProgressBar ctrl ) : void
dc System.Drawing.Graphics
clip_rect System.Drawing.Rectangle
ctrl System.Windows.Forms.ProgressBar
return void
		public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl) 
		{
			Rectangle client_area = ctrl.client_area;
			
			/* Draw border */
			CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenOuter, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom & ~Border3DSide.Middle, ColorControl);
			
			/* Draw Blocks */
			int draw_mode = 0;
			int max_blocks = int.MaxValue;
			int start_pixel = client_area.X;
			draw_mode = (int) ctrl.Style;

			switch (draw_mode) {
			case 1: { // Continuous
				int pixels_to_draw;
				pixels_to_draw = (int)(client_area.Width * ((double)(ctrl.Value - ctrl.Minimum) / (double)(Math.Max(ctrl.Maximum - ctrl.Minimum, 1))));
				dc.FillRectangle (ResPool.GetSolidBrush (ctrl.ForeColor), new Rectangle (client_area.X, client_area.Y, pixels_to_draw, client_area.Height));
				break;
			}
			case 2: // Marquee
				if (XplatUI.ThemesEnabled) {
					int ms_diff = (int) (DateTime.Now - ctrl.start).TotalMilliseconds;
					double percent_done = (double) ms_diff / ProgressBarMarqueeSpeedScaling 
						% (double)ctrl.MarqueeAnimationSpeed / (double)ctrl.MarqueeAnimationSpeed;
					max_blocks = 5;
					start_pixel = client_area.X + (int) (client_area.Width * percent_done);
				}
				
				goto case 0;
			case 0:
			default:  // Blocks
				Rectangle block_rect;
				int space_betweenblocks = ProgressBarChunkSpacing;
				int block_width;
				int increment;
				int barpos_pixels;
				int block_count = 0;
				
				block_width = ProgressBarGetChunkSize (client_area.Height);
				block_width = Math.Max (block_width, 0); // block_width is used to break out the loop below, it must be >= 0!
				barpos_pixels = (int)(((double)(ctrl.Value - ctrl.Minimum) * client_area.Width) / (Math.Max (ctrl.Maximum - ctrl.Minimum, 1)));
				increment = block_width + space_betweenblocks;
				
				block_rect = new Rectangle (start_pixel, client_area.Y, block_width, client_area.Height);
				while (true) {
					if (max_blocks != int.MaxValue) {
						if (block_count >= max_blocks)
							break;
						if (block_rect.X > client_area.Width)
							block_rect.X -= client_area.Width;
					} else {
						if ((block_rect.X - client_area.X) >= barpos_pixels)
							break;
					}
					
					if (clip_rect.IntersectsWith (block_rect) == true) {				
						dc.FillRectangle (ResPool.GetSolidBrush (ctrl.ForeColor), block_rect);
					}				
					
					block_rect.X  += increment;
					block_count++;
				}
				break;
			
			}
		}
		
ThemeWin32Classic