【问题标题】:How to scroll in TabPages/TabControl如何在 TabPages/TabControl 中滚动
【发布时间】:2012-09-25 21:51:54
【问题描述】:

我有 3 页的 tabcontrol。在标签页中放置了列表视图。列表视图可以比标签页本身更大。

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

我尝试通过以下来源解决此问题:

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

但是没有显示卷轴。我哪里错了?

谁能帮帮我?

谢谢你的帮助。

【问题讨论】:

  • 为什么不让列表视图可滚动?
  • 你是怎么做到的?使用可滚动=真;我没有发现任何区别。
  • lvwAlbums.Parent = pctlDatabeheer.TabPages[1]; lvwAlbums.Left = 0; lvwAlbums.Top = 0; lvwAlbums.Width = pctlDatabeheer.TabPages[1].Width - 35; lvwAlbums.Height = pctlDatabeheer.TabPages[1].Height; lvwAlbums.SmallImageList = iltListView; lvwAlbums.FullRowSelect = true; lvwAlbums.Anchor = AnchorStyles.Bottom | AnchorStyles.左 | AnchorStyles.Right | AnchorStyles.Top;
  • 是锚定。移除底部的锚定。如果这对您有帮助,请记得点赞并接受。

标签: c# winforms


【解决方案1】:

我创建了一个新的 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].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; 

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

【讨论】:

  • 谢谢。但它要复杂得多。我添加了一个面板作为列表视图的父级。 (到目前为止)。但是 TabControl 比窗体大。现在我正在寻找原因?
猜你喜欢
  • 2011-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-26
  • 2017-07-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多