110,502
社区成员
发帖
与我相关
我的任务
分享
private void button1_Click(object sender, EventArgs e)
{
int n = 200;
Label[] la = new Label[n];
for (int i = 0; i < n; i++)
{
la[i] = new Label();
la[i].Text = Convert.ToString(i);
la[i].BorderStyle = BorderStyle.FixedSingle;
flowLayoutPanel1.Controls.Add(la[i]);
}
}
void Form1_MouseWheel(object sender, MouseEventArgs e)
{
Point aPoint = new Point(e.X, e.Y);
aPoint.Offset(this.Location.X, this.Location.Y);
Rectangle aRec1 = new Rectangle(flowLayoutPanel1.Location.X, flowLayoutPanel1.Location.Y, flowLayoutPanel1.Width, flowLayoutPanel1.Height);
Rectangle aRec2 = new Rectangle(flowLayoutPanel2.Location.X, flowLayoutPanel2.Location.Y, flowLayoutPanel2.Width, flowLayoutPanel2.Height);
if (RectangleToScreen(aRec1).Contains(aPoint))
flowLayoutPanel1.AutoScrollPosition = new Point(0, flowLayoutPanel1.VerticalScroll.Value - e.Delta / 80);
if (RectangleToScreen(aRec2).Contains(aPoint))
flowLayoutPanel2.AutoScrollPosition = new Point(0, flowLayoutPanel2.VerticalScroll.Value - e.Delta / 80);
}