AForge.Controls.Histogram.OnPaint C# (CSharp) Method

OnPaint() protected method

Paint the control.
protected OnPaint ( PaintEventArgs pe ) : void
pe PaintEventArgs Data for Paint event.
return void
		protected override void OnPaint(PaintEventArgs pe)
		{
			var g = pe.Graphics;
			// drawing area's width and height
			width = ((values == null) || (vertical == true)) ?
				ClientRectangle.Width - 2 :
			   System.Math.Min(values.Length,ClientRectangle.Width - 2);

			height = ((values == null) || (vertical == false)) ?
				ClientRectangle.Height - 2 :
			   System.Math.Min(values.Length,ClientRectangle.Height - 2);

			var x = 1;
			var y = 1;
			int value;

			// draw rectangle around the image
			g.DrawRectangle(blackPen,x - 1,y - 1,width + 1,height + 1);

			if (values != null)
			{
				var start = System.Math.Min(this.start,this.stop);
				var stop = System.Math.Max(this.start,this.stop);

				if (tracking)
				{
					// fill region of selection
					Brush brush = new SolidBrush(Color.FromArgb(92,92,92));

					if (vertical)
					{
						g.FillRectangle(brush,x,y + start,width,Math.Abs(start - stop) + 1);
					}
					else
					{
						g.FillRectangle(brush,x + start,y,Math.Abs(start - stop) + 1,height);
					}
					brush.Dispose();
				}

				if (max != 0)
				{
					// scaling factor
					var factor = ((vertical) ? width : height) /
						((logarithmic) ? maxLogarithmic : max);

					// draw histogram
					for (int i = 0, len = (vertical) ? height : width; i < len; i++)
					{
						if (logarithmic)
						{
							value = (values[i] == 0) ? 0 : (int)(Math.Log10(values[i]) * factor);
						}
						else
						{
							value = (int)(values[i] * factor);
						}

						if (value != 0)
						{
							if (vertical)
							{
								g.DrawLine(((tracking) && (i >= start) && (i <= stop)) ? whitePen : drawPen,
									new Point(x,y + i),
									new Point(x + value,y + i)
									);
							}
							else
							{
								g.DrawLine(((tracking) && (i >= start) && (i <= stop)) ? whitePen : drawPen,
									new Point(x + i,y + height - 1),
									new Point(x + i,y + height - value)
									);
							}
						}
					}
				}
			}

			// Calling the base class OnPaint
			base.OnPaint(pe);
		}