MouseWheel事件不會觸發 。當使用任何帶有滾動條的控件(ListBox,Panel,TextBox)和滾動條時,鼠標滾輪事件不會觸發(在C#Windows窗體中)
要重現問題:
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();
}
}
也許問題是鼠標, 我使用「聯想USB光電鼠標」 (默認配置 「線輪按鈕」功能「快速/自動滾動」) – halorty 2010-01-20 07:32:49
我使用:Windows Vista中商務大,.Net框架3.5 SP1 ,Visual Studio 2008標準版(所有官方修補程序)。構建調試:目標框架= .Net Framework 3。5,輸出類型= Windows應用程序 – halorty 2010-01-20 08:09:41
鼠標配置: 控制面板/鼠標/滾輪/輪 - >啓用通用滾動; 控制面板/鼠標/車輪/車輪按鈕 - >快速/自動滾動; 控制面板/鼠標/滾輪/滾動速度 - >滾動=每行10行; – halorty 2010-01-20 08:14:24