使用带有scrolbars任何控制(在C#Windows窗体)当鼠标滚轮不会触发事件 [英] MouseWheel event doesn't fire when using any control with scrolbars (in C# Windows Forms)
问题描述
鼠标滚轮事件确实时我正在使用的任何控件(列表框,面板,文本框)的滚动条
要重现问题不火
:
公共Form1类:表格
{
私人只读按钮按钮1;
私人只读文本框textBox1的;
私人无效button1_MouseWheel(对象发件人,MouseEventArgs E)
{
的ToString(); //不火的时候,取消注释行跌破
}
公共Form1中()
{
按钮1 =新的Button();
textBox1的=新的TextBox();
SuspendLayout();
button1.Location =新System.Drawing.Point(80,105);
button1.Size =新System.Drawing.Size(75,23);
button1.MouseWheel + = button1_MouseWheel;
button1.Click + =的button1_Click;
textBox1.Location =新System.Drawing.Point(338,105);
//textBox1.Multiline = TRUE; //取消注释此
//textBox1.ScrollBars = ScrollBars.Vertical; //取消注释此
textBox1.Size =新System.Drawing.Size(100,92);
ClientSize =新System.Drawing.Size(604,257);
Controls.Add被(textBox1中);
Controls.Add被(按钮1);
ResumeLayout(假);
PerformLayout();
}
//单击该按钮将焦点,但即使我做明确的焦点()或选择()
//仍然不起作用
私人无效的button1_Click(对象发件人,发送System.EventArgs)
{
button1.Focus();
button1.Select();
}
}
< STRONG>我找到了解决方案,gility是默认的鼠标配置。的联想USB光电鼠标的默认配置是:
控制面板/鼠标/轮/线轮 - > 启用通用滚动;
我更改为:
控制面板/鼠标/轮/线轮 - > 使用的Microsoft Office 97滚动仿真仅
现在在.NET代码与鼠标滚轮工作的关注 控制的。
但问题是:
- 如何解决它在.NET代码?
- 我怎么能检测.NET代码这种情况呢?
任何想法?
MouseWheel event doesn't fire when I' am using any control (ListBox, Panel, TextBox) with scrollbars.
To reproduce problem:
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();
}
}
I found solution, gility is default "Mouse Configuration". Lenovo USB Optical Wheel Mouse default configuration is:
Control Panel/Mouse/Wheel/Whell->Enable Universal Scrolling;
I changed to:
Control Panel/Mouse/Wheel/Whell->Use Microsoft Office 97 Scrolling Emulation Only
Now in .net code MouseWheel working with Focused Control.
But questions are:
- how can I fix it in .net code?
- how can I detect this situation in .net code?
Any ideas ?
这篇关于使用带有scrolbars任何控制(在C#Windows窗体)当鼠标滚轮不会触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!