如何在流布局面板中滚动而不在窗口窗体中显示滚动条
本文关键字:窗口 窗体 显示 滚动条 滚动 流布局 | 更新日期: 2023-09-27 18:36:43
我正在WinForms中开发触摸屏POS。
我有一个流程布局面板并动态添加按钮,但我不想显示滚动条。
我使用 2 个按钮来滚动,所以请帮助我如何在不显示滚动条的情况下滚动
尝试将 FlowLayoutPanel 放在具有以下属性的另一个面板中:
flowLayoutPanel1.AutoScroll = false;
flowLayoutPanel1.AutoSize = true;
flowLayoutPanel1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
从这里开始,您必须根据两个按钮控制面板内 FlowLayoutPanel1 的位置(也应该具有 AutoScroll = false;
)。
取两个按钮 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);
}
}
}