c# Panel with autoscroll - Srollbar position reset on a control focus

前端 未结 2 1269
夕颜
夕颜 2021-02-04 04:44

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.

2条回答
  •  梦谈多话
    2021-02-04 05:24

    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;
        }
    }
    

提交回复
热议问题