1
votes

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.

flowlayoutexample

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


    }
2
one of the key reasons this doesn't work is you used = instead of += / -=, but that value property acts strange with += anyway, see my answer below for a complete answer that fixes what you did here :) - chrispepper1989
Out of interest why are you doing it in code? why not just use flowLayoutPanel1.AutoScroll = true; flowLayoutPanel1.VerticalScroll.Visible = true; - chrispepper1989
becuase this program will be use touch screen machine.So I have to put large button for scrolling :) - Sezer Erdogan

2 Answers

1
votes

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;
    }
0
votes

What type of scroll are you trying to achieve, would this code do you?

How to Programmatically Scroll a Panel

This allows you to scroll per control, rather than a "smooth" scroll but I think this would work for your application.