父容器中子Form自动滚动到底部,如何设置加载时滚动到顶部?
解决子Form加载时自动滚动到底部的问题

可以通过以下两种方法实现子Form加载时滚动到顶部:
在子Form的
Load事件中设置滚动位置:
打开子Form的代码文件,找到Load事件处理方法,添加如下代码:private void ChildForm_Load(object sender, EventArgs e) { // 将垂直滚动条滚动到顶部 this.AutoScrollPosition = new Point(0, 0); }若直接设置不生效,可尝试先触发一次滚动再重置位置:
private void ChildForm_Load(object sender, EventArgs e) { this.AutoScrollPosition = new Point(1, 1); this.AutoScrollPosition = new Point(0, 0); }在父窗体添加子Form到TabPage后设置滚动位置:
如果你是动态添加子Form到TabPage,可在添加完成后直接设置:ChildForm childForm = new ChildForm(); childForm.TopLevel = false; childForm.FormBorderStyle = FormBorderStyle.None; childForm.Dock = DockStyle.Fill; tabPage1.Controls.Add(childForm); childForm.Show(); // 强制子Form滚动到顶部 childForm.AutoScrollPosition = new Point(0, 0);
另外要确认子Form的AutoScroll属性确实为true,且没有其他代码在加载过程中修改滚动位置。
内容的提问来源于stack exchange,提问作者Keelan McCarthy
相关产品推荐
相关产品推荐

