System.Windows.Forms.ScrollableControl.ScrollToControl C# (CSharp) Method

ScrollToControl() protected method

protected ScrollToControl ( Control activeControl ) : Point
activeControl Control
return System.Drawing.Point
		protected virtual Point ScrollToControl (Control activeControl)
		{
			int corner_x;
			int corner_y;
			
			Rectangle within = new Rectangle ();
			within.Size = ClientSize;
			
			
			// If the control is above the top or the left, move it down and right until it aligns 
			// with the top/left.
			// If the control is below the bottom or to the right, move it up/left until it aligns
			// with the bottom/right, but do never move it further than the top/left side.
			int x_diff = 0, y_diff = 0;
			
			if (activeControl.Top <= 0 || activeControl.Height >= within.Height)
				y_diff = -activeControl.Top; else if (activeControl.Bottom > within.Height)
				y_diff = within.Height - activeControl.Bottom;
			
			if (activeControl.Left <= 0 || activeControl.Width >= within.Width)
				x_diff = -activeControl.Left; else if (activeControl.Right > within.Width)
				x_diff = within.Width - activeControl.Right;
			
			corner_x = AutoScrollPosition.X + x_diff;
			corner_y = AutoScrollPosition.Y + y_diff;
			
			return new Point (corner_x, corner_y);
		}