• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

如何在c#中为流布局面板创建自定义滚动按钮#

c/c++ 来源:Sezer Erdogan 6次浏览

我必须为流布局面板项目创建向上和向下按钮垂直滚动。我该怎么办?我会为POS做这个表格。如何在c#中为流布局面板创建自定义滚动按钮#

我这样做,但它不工作:我有很多按钮,他们有87尺寸高度:我添加了代码和图片。

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


    } 


===========解决方案如下:

或者你可能只是想设置“自动滚动”假下面的代码实现适当的编程滚动:

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)