如何在FLOWLAYOUTPANEL上添加添加滚轮

irearn 2009-02-08 01:45:51

从前有一个FORM
FORM里有个FLOWLAYOUTPANEL
我通过如下方法在PANEL里面新建很多LABEL

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]);
}
}


于是PANEL不够大了,出现了一个纵向的滚动条
但是好像这个滚动条却不支持滚轮
怎么才能支持滚轮呢?
...全文
510 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
irearn 2009-02-09
  • 打赏
  • 举报
回复
我会了..
用PANEL自己的滚动条就可以了
为FORM添加一个MOUSEWHEEL事件的监听器
然后判断鼠标悬停是否实在PANEL上就OK了...

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

}

irearn 2009-02-08
  • 打赏
  • 举报
回复
能不能说的再详细一些...
我刚刚接触C#
irearn 2009-02-08
  • 打赏
  • 举报
回复
能不能说的再详细一些...
我刚刚接触C#
JeffrySun 2009-02-08
  • 打赏
  • 举报
回复
先加一个滚动条,然后在滚动条内部动态计算滚动步长,最大值

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧