This is for a windows form.
Panel has AutoScroll = True
I am adding panels dynamically to the main panel which end up exceeding the main panel display rectangle.
I found the answer to the problem I was having here: Answer
public class CustomPanel : System.Windows.Forms.Panel
{
protected override System.Drawing.Point ScrollToControl(System.Windows.Forms.Control activeControl)
{
// Returning the current location prevents the panel from
// scrolling to the active control when the panel loses and regains focus
return this.DisplayRectangle.Location;
}
}
Thanks, this works great except I had to adjust for the panel's padding at the bottom. Just an FYI to any others who may be seeing some offsets.
protected override System.Drawing.Point ScrollToControl(System.Windows.Forms.Control activeControl)
{
Point retPt = DisplayRectangle.Location;
retPt.Offset(new Point(-1*Padding.Left, -1*Padding.Bottom));
return retPt;
}