如何触发 FlowLayoutPanel 的滚动事件?
How to trigger scroll event of a FlowLayoutPanel?
这是我的代码:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
for (int i = 0; i < 10; i++) {
Button btn = new Button();
btn.Text = "TEST";
btn.Height = 35;
this.flowLayoutPanel1.Controls.Add(btn);
}
this.flowLayoutPanel1.AutoScroll = true;
this.flowLayoutPanel1.Scroll += FlowLayoutPanel1_Scroll;
}
private void FlowLayoutPanel1_Scroll(object sender, ScrollEventArgs e) {
MessageBox.Show("Event Triggered");
}
}
下面是 UI 的样子:
当我在 flowlayoutpanel 中使用鼠标滚轮滚动时,似乎没有触发滚动事件
解决方案应该不难找到,但是我坚持了几个小时..
谁能给我指出一些方向?谢谢!!
有一个特殊的MouseWheel事件捕获了这个
flowLayoutPanel1.MouseWheel += FlowLayoutPanel1_MouseWheel;
private void FlowLayoutPanel1_MouseWheel(object sender, MouseEventArgs e)
{
Console.WriteLine("Scrolling Wheel");
}
这是我的代码:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
for (int i = 0; i < 10; i++) {
Button btn = new Button();
btn.Text = "TEST";
btn.Height = 35;
this.flowLayoutPanel1.Controls.Add(btn);
}
this.flowLayoutPanel1.AutoScroll = true;
this.flowLayoutPanel1.Scroll += FlowLayoutPanel1_Scroll;
}
private void FlowLayoutPanel1_Scroll(object sender, ScrollEventArgs e) {
MessageBox.Show("Event Triggered");
}
}
下面是 UI 的样子:
当我在 flowlayoutpanel 中使用鼠标滚轮滚动时,似乎没有触发滚动事件
解决方案应该不难找到,但是我坚持了几个小时.. 谁能给我指出一些方向?谢谢!!
有一个特殊的MouseWheel事件捕获了这个
flowLayoutPanel1.MouseWheel += FlowLayoutPanel1_MouseWheel;
private void FlowLayoutPanel1_MouseWheel(object sender, MouseEventArgs e)
{
Console.WriteLine("Scrolling Wheel");
}