如何在 C# 中为流布局面板创建自定义滚动按钮
how to create custom scroll button for flow layout panel in c#
我必须为流布局面板创建向上和向下按钮垂直滚动 items.How 可以吗?我会为 POS 做这个表格。
我这样做了,但它不起作用:我有很多按钮,它们的高度为 87:我添加了代码和图片。
private void btnScrollUp_Click(object sender, EventArgs e)
{
flowLayoutPanel1.VerticalScroll.Value = flowLayoutPanel1.VerticalScroll.LargeChange-1 ;
flowLayoutPanel1.PerformLayout();
}
private void btnScrollDown_Click(object sender, EventArgs e)
{
flowLayoutPanel1.VerticalScroll.Value = flowLayoutPanel1.VerticalScroll.LargeChange+ 1;
flowLayoutPanel1.PerformLayout();
}
您想要实现什么类型的卷轴,您会使用这段代码吗?
How to Programmatically Scroll a Panel
这允许您滚动每个控件,而不是 "smooth" 滚动,但我认为这适用于您的应用程序。
或者您可能只想将 "AutoScroll" 设置为 false 以下代码实现正确的编程滚动:
public Form1()
{
InitializeComponent();
flowLayoutPanel1.AutoScroll = false;
}
public int scrollValue = 0;
public int ScrollValue
{
get
{
return scrollValue;
}
set
{
scrollValue = value;
if (scrollValue < flowLayoutPanel1.VerticalScroll.Minimum )
{
scrollValue = flowLayoutPanel1.VerticalScroll.Minimum;
}
if (scrollValue > flowLayoutPanel1.VerticalScroll.Maximum)
{
scrollValue = flowLayoutPanel1.VerticalScroll.Maximum;
}
flowLayoutPanel1.VerticalScroll.Value = scrollValue;
flowLayoutPanel1.PerformLayout();
}
}
private void Add_Control(object sender, EventArgs e)
{
flowLayoutPanel1.Controls.Add(new Button(){Width = flowLayoutPanel1.Width, Height = 87});
}
private void UpClick(object sender, EventArgs e)
{
ScrollValue -= flowLayoutPanel1.VerticalScroll.LargeChange;
}
private void DownClick(object sender, EventArgs e)
{
ScrollValue += flowLayoutPanel1.VerticalScroll.LargeChange;
}
我必须为流布局面板创建向上和向下按钮垂直滚动 items.How 可以吗?我会为 POS 做这个表格。
我这样做了,但它不起作用:我有很多按钮,它们的高度为 87:我添加了代码和图片。
private void btnScrollUp_Click(object sender, EventArgs e)
{
flowLayoutPanel1.VerticalScroll.Value = flowLayoutPanel1.VerticalScroll.LargeChange-1 ;
flowLayoutPanel1.PerformLayout();
}
private void btnScrollDown_Click(object sender, EventArgs e)
{
flowLayoutPanel1.VerticalScroll.Value = flowLayoutPanel1.VerticalScroll.LargeChange+ 1;
flowLayoutPanel1.PerformLayout();
}
您想要实现什么类型的卷轴,您会使用这段代码吗?
How to Programmatically Scroll a Panel
这允许您滚动每个控件,而不是 "smooth" 滚动,但我认为这适用于您的应用程序。
或者您可能只想将 "AutoScroll" 设置为 false 以下代码实现正确的编程滚动:
public Form1()
{
InitializeComponent();
flowLayoutPanel1.AutoScroll = false;
}
public int scrollValue = 0;
public int ScrollValue
{
get
{
return scrollValue;
}
set
{
scrollValue = value;
if (scrollValue < flowLayoutPanel1.VerticalScroll.Minimum )
{
scrollValue = flowLayoutPanel1.VerticalScroll.Minimum;
}
if (scrollValue > flowLayoutPanel1.VerticalScroll.Maximum)
{
scrollValue = flowLayoutPanel1.VerticalScroll.Maximum;
}
flowLayoutPanel1.VerticalScroll.Value = scrollValue;
flowLayoutPanel1.PerformLayout();
}
}
private void Add_Control(object sender, EventArgs e)
{
flowLayoutPanel1.Controls.Add(new Button(){Width = flowLayoutPanel1.Width, Height = 87});
}
private void UpClick(object sender, EventArgs e)
{
ScrollValue -= flowLayoutPanel1.VerticalScroll.LargeChange;
}
private void DownClick(object sender, EventArgs e)
{
ScrollValue += flowLayoutPanel1.VerticalScroll.LargeChange;
}