1. 创建FlowLayoutPanel控件
注意请把AutoScroll设置为true。
FlowLayoutPanel flpPanel= new System.Windows.Forms.FlowLayoutPanel();
flpPanel.AutoScroll = true;
flpPanel.Dock = System.Windows.Forms.DockStyle.Fill;
flpPanel.Location = new System.Drawing.Point(0, 0);
flpPanel.Name = "flpPanel";
flpPanel.Size = new System.Drawing.Size(252, 61);
flpPanel.TabIndex = 1;
2. 往FlowLayoutPanel动态创建控件
往FlowLayoutPanel动态创建100个Button,只要能实现显示垂直滚动条即可。
int butonCount = 100;
for(var i=0 ; i < buttonCount ; i++)
{
var button = new Button();
button.Name = String.Contact("btn",i.ToString());
button.Text = button.Name;
flpPanel.Controls.Add(button);
}
// 调用第3点的类进行绑定MouseDown及MouseMove事件
new TouchScroll(flpPanel);
3. 为FlowLayoutPanel处理MouseDown及MouseMove事件
创建TouchScroll类