【发布时间】:2011-01-06 20:28:56
【问题描述】:
MouseWheel 事件不会触发 当我使用带有滚动条的任何控件(ListBox、Panel、TextBox)时。
重现问题:
public class Form1 : Form
{
private readonly Button button1;
private readonly TextBox textBox1;
private void button1_MouseWheel(object sender, MouseEventArgs e)
{
ToString(); // doesn't fire when uncomment lines below
}
public Form1()
{
button1 = new Button();
textBox1 = new TextBox();
SuspendLayout();
button1.Location = new System.Drawing.Point(80, 105);
button1.Size = new System.Drawing.Size(75, 23);
button1.MouseWheel += button1_MouseWheel;
button1.Click += button1_Click;
textBox1.Location = new System.Drawing.Point(338, 105);
//textBox1.Multiline = true; // uncomment this
//textBox1.ScrollBars = ScrollBars.Vertical; // uncomment this
textBox1.Size = new System.Drawing.Size(100, 92);
ClientSize = new System.Drawing.Size(604, 257);
Controls.Add(textBox1);
Controls.Add(button1);
ResumeLayout(false);
PerformLayout();
}
// Clicking the button sets Focus, but even I do it explicit Focus() or Select()
// still doesn't work
private void button1_Click(object sender, System.EventArgs e)
{
button1.Focus();
button1.Select();
}
}
【问题讨论】:
-
可能问题出在鼠标上,我用的是“Lenovo USB Optical Wheel Mouse”(默认配置“Whell Button”功能“Quick/AutoScroll”)
-
我使用:Windows Vista Buisness、.Net Framework 3.5 SP1、Visual Studio 2008 Standard Edition(所有官方修补程序)。构建调试:目标框架 = .Net Framework 3.5,输出类型 = Windows 应用程序
-
鼠标配置:控制面板/鼠标/滚轮/Well->启用通用滚动;控制面板/鼠标/滚轮/滚轮按钮->快速/自动滚动;控制面板/鼠标/滚轮/滚动速度->滚动=每秒 10 行;
-
我正在努力解决同样的问题。我认为许多人将其与“专注与悬停”问题混淆了。我有相同的基于 ScrollableControl 的控件,它要么触发 OnMouseWheel,要么不触发,具体取决于它当前是否显示滚动条。我认为滚动条以某种方式捕获了滚轮事件,但我还没有充分研究这个问题。 OP 是否有机会找到解决方案?
标签: c# winforms events scrollbar mousewheel