none
WinForm flowLayoutPanel控件的滚动条问题 RRS feed

  • 问题

  • 窗体中有一个flowLayoutPanel控件,flowLayoutPanel中有许多GroupBox控件,从上往下排列,一行一个GroupBox控件

    另外有一竖排按钮,按钮进行定位GroupBox,点击某一个按钮,滚动条定位到某一个GroupBox位置上,类似于网页中的锚定功能。

    求大神给点提示。

    2013年12月10日 14:55

答案

  • 你好:

    FlowLayoutPanel控件有关于滚轴的属性,通过这个属性可以自定义的设置滚轴的位置,下面是上滚和下滚的代码:

    private void button1_Click(object sender, EventArgs e)
            {
                int i=this.flowLayoutPanel1.VerticalScroll.Value + this.flowLayoutPanel1.VerticalScroll.SmallChange;
                if (this.flowLayoutPanel1.VerticalScroll.Maximum < i)
                {
                    this.flowLayoutPanel1.VerticalScroll.Value = this.flowLayoutPanel1.VerticalScroll.Maximum;
                }
                else
                {
                    this.flowLayoutPanel1.VerticalScroll.Value = i;
                }
    
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                int i = this.flowLayoutPanel1.VerticalScroll.Value - this.flowLayoutPanel1.VerticalScroll.SmallChange;
                if (this.flowLayoutPanel1.VerticalScroll.Minimum > i)
                {
                    this.flowLayoutPanel1.VerticalScroll.Value = this.flowLayoutPanel1.VerticalScroll.Minimum;
                }
                else
                {
                    this.flowLayoutPanel1.VerticalScroll.Value = i;
                }
    
            }

    滚轴的的位置有一个最大值和最小值,滚动过程不能超过这个范围,否则报错。你可以根据FlowLayoutPanel控件中的其他内置控件的位置来判断滚轴值的大小,用代码来设定就可以了。

    这里有一片文章讲解了如何用方向键来修改滚轴的位置,估计对你有用:

    Making FlowLayoutPanel Scroll Using Arrow Keys, Page Up, Page Down


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2013年12月11日 7:47
    版主