如何在 Windows 窗体中使用 FlowLayoutPanel 实现滚动条不可见的滚动

4

我正在WinForms上开发一个触摸屏POS系统。

我使用流式布局面板(flowlayoutpanel)并动态添加按钮,但我不想显示滚动条。

我使用了两个按钮来进行滚动,因此请帮助我如何在不显示滚动条的情况下进行滚动。


它对我没用,请问您可以发布设置和配置吗? - Smith
2个回答

8

尝试将FlowLayoutPanel放置在具有以下属性的另一个面板中:

flowLayoutPanel1.AutoScroll = false;
flowLayoutPanel1.AutoSize = true;
flowLayoutPanel1.AutoSizeMode = AutoSizeMode.GrowAndShrink;

从这里开始,你需要控制 FlowLayoutPanel1 在面板内的位置(该面板应该也具有 AutoScroll=false; ),以便根据你的两个按钮进行操作。


我能向这个添加缓动或页面滚动吗?所谓的页面滚动是指,在左侧或右侧点击后,所有可见控件都被滚动到显示新的可见控件。 - Smith

1
取两个按钮btnLeft和btnRight,尝试使用以下代码:
private void btnLeft_Click(object sender, EventArgs e)
{
    if (flowPanelItemCategory.Location.X <= xpos)
    {
        xmin = flowPanelItemCategory.HorizontalScroll.Minimum;
        if (flowPanelItemCategory.Location.X >= xmin)
        {
            xpos -= 100;
            flowPanelItemCategory.Location = new Point(xpos, 0);
        }
    }
}

private void btnRight_Click(object sender, EventArgs e)
{
    if (flowPanelItemCategory.Location.X <= xpos)
    {
        xmax = flowPanelItemCategory.HorizontalScroll.Maximum;
        if (flowPanelItemCategory.Location.X < xmax)
        {
            xpos += 100;
            flowPanelItemCategory.Location = new Point(xpos, 0);
        }
    }
}

它对我不起作用,你能发布设置和配置吗? - Smith

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接