I have to create up and down button vertical scrolling for flow layout panel items.How can I do ? I will do this form for POS.
I done this way but it is not working : I have lots of buttons they have size 87 height : I added code and picture.
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();
}
Alternatively you might just want to set "AutoScroll" to false the following code implements proper programmatic scroll:
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;
}