You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

解决子Form加载时自动滚动到底部的问题

包含子Form的TabPage窗体

可以通过以下两种方法实现子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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 17:51:18