简体   繁体   English

如何在TabPages / TabControl中滚动

[英]How to scroll in TabPages/TabControl

I've tabcontrol with 3 pages. 我有3页的tabcontrol。 Within the tabpages are placed listviews. 在标签页中放置列表视图。 The listviews can be bigger than the tabpage itself. 列表视图可以大于标签页本身。

I wanna add scrollbars on the tabpages 我想在标签页上添加滚动条

I tried to solve this with the following source: 我尝试通过以下来源解决此问题:

  lvwAlbums.Parent = pctlDatabeheer.TabPages[1];
            lvwAlbums.Left = 0;
            lvwAlbums.Top = 0;
            lvwAlbums.Width = pctlDatabeheer.TabPages[1].Width - 35;
            lvwAlbums.Height = 1000;// pctlDatabeheer.TabPages[1].Height;
            lvwAlbums.SmallImageList = iltListView;
            lvwAlbums.FullRowSelect = true;
            lvwAlbums.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;

 foreach (TabPage _Page in pctlDatabeheer.TabPages)
            {
                _Page.AutoScroll = true;
                _Page.AutoScrollMargin = new System.Drawing.Size(20, 20);
                _Page.AutoScrollMinSize = new System.Drawing.Size(_Page.Width, _Page.Height);
            }

But the scroll are not shown. 但是没有显示滚动条。 What do I wrong? 我怎么了

Can anybody help me? 有谁能够帮助我?

Thank yopu for your help. 感谢yopu的帮助。

I created a new Visual Studio WinForms project. 我创建了一个新的Visual Studio WinForms项目。 Kept the form designer completely empty and used your code: 保持表单设计器完全为空,并使用了您的代码:

public Form1()
{
    InitializeComponent();

    // Make TabControl
    TabControl tabControl1 = new TabControl();
    tabControl1.TabPages.Add(new TabPage());
    tabControl1.TabPages.Add(new TabPage());
    tabControl1.Dock = DockStyle.Fill;
    this.Controls.Add(tabControl1);

    // Make long ListView and add to first tab
    ListView listView1 = new ListView();
    listView1.Location = new Point(0, 0);
    listView1.Height = 1000;
    tabControl1.TabPages[0].Controls.Add(listView1);

    // Your code
    foreach (TabPage _Page in tabControl1.TabPages)
    {
        _Page.AutoScroll = true;
        _Page.AutoScrollMargin = new System.Drawing.Size(20, 20);
        _Page.AutoScrollMinSize = new System.Drawing.Size(_Page.Width, _Page.Height);
    }
}

Works perfectly fine. 工作完美。 I suspect you have something else wrong but I can't see that or troubleshoot it without seeing your code. 我怀疑您还有其他问题,但是在看不到您的代码的情况下无法看到它或对其进行故障排除。

EDIT: Now that you posted some more code, your issue is with your list box: 编辑:现在您发布了更多的代码,您的问题与您的列表框:

lvwAlbums.Parent = pctlDatabeheer.TabPages[1];
lvwAlbums.Left = 0;
lvwAlbums.Top = 0;
lvwAlbums.Width = pctlDatabeheer.TabPages[1].Width - 35;
lvwAlbums.Height = 1000;
lvwAlbums.SmallImageList = iltListView;
lvwAlbums.FullRowSelect = true;
// Here is the issue!
// Do not anchor to the bottom or scrolling won't work
lvwAlbums.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; 

Don't anchor the control to the bottom. 不要将控件固定在底部。 That is causing you the issue. 那就是你的问题。 You cannot anchor to the bottom and then scroll. 您无法定位到底部,然后滚动。 The other anchors are fine. 其他锚很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM