Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在TabPages/TabControl中滚动_C#_Winforms - Fatal编程技术网

C# 如何在TabPages/TabControl中滚动

C# 如何在TabPages/TabControl中滚动,c#,winforms,C#,Winforms,我已经用3页的tabcontrol了。在选项卡中,页面放置在ListView中。ListView可以比tabpage本身大 我想在标签页上添加滚动条 我试图通过以下来源解决这个问题: lvwAlbums.Parent = pctlDatabeheer.TabPages[1]; lvwAlbums.Left = 0; lvwAlbums.Top = 0; lvwAlbums.Width = pctlDatabeheer.T

我已经用3页的tabcontrol了。在选项卡中,页面放置在ListView中。ListView可以比tabpage本身大

我想在标签页上添加滚动条

我试图通过以下来源解决这个问题:

  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);
            }
但卷轴没有显示。我错了什么

有人能帮我吗


感谢yopu的帮助。

我创建了一个新的Visual Studio WinForms项目。使窗体设计器完全为空并使用您的代码:

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);
    }
}
很好用。我怀疑您还有其他问题,但如果没有看到您的代码,我无法看到这一点或排除故障

编辑:现在您发布了更多代码,您的问题在于您的列表框:


不要将控件锚定到底部。这就是问题的根源。您不能锚定到底部然后滚动。其他锚都很好。

我创建了一个新的Visual Studio WinForms项目。使窗体设计器完全为空并使用您的代码:

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);
    }
}
很好用。我怀疑您还有其他问题,但如果没有看到您的代码,我无法看到这一点或排除故障

编辑:现在您发布了更多代码,您的问题在于您的列表框:


不要将控件锚定到底部。这就是问题的根源。您不能锚定到底部然后滚动。其他锚都很好。

为什么不让列表视图可滚动?如何实现?可滚动=真;我没有看到任何区别。lvwAlbums.Parent=pctlDatabeheer.TabPages[1];lvwAlbums.Left=0;lvwAlbums.Top=0;lvwAlbums.Width=pctlDatabeheer.TabPages[1]。宽度-35;lvwAlbums.Height=pctlDatabeheer.TabPages[1]。高度;lvwAlbums.SmallImageList=iltListView;lvwAlbums.FullRowSelect=true;lvwAlbums.Anchor=AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;这是锚定。卸下底部的锚固件。如果这对您有帮助,请记住向上投票并接受。为什么不让列表视图可滚动?您是如何做到的?可滚动=真;我没有看到任何区别。lvwAlbums.Parent=pctlDatabeheer.TabPages[1];lvwAlbums.Left=0;lvwAlbums.Top=0;lvwAlbums.Width=pctlDatabeheer.TabPages[1]。宽度-35;lvwAlbums.Height=pctlDatabeheer.TabPages[1]。高度;lvwAlbums.SmallImageList=iltListView;lvwAlbums.FullRowSelect=true;lvwAlbums.Anchor=AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;这是锚定。卸下底部的锚固件。如果这对你有帮助,请记得投票并接受。谢谢。但它要复杂得多。我添加了一个面板作为listview的父级。到目前为止。但是TabControl比表单大。现在我在找原因,谢谢。但它要复杂得多。我添加了一个面板作为listview的父级。到目前为止。但是TabControl比表单大。现在我在寻找原因?