当 TextBox 可滚动时,MouseScroll 事件不会触发
我发现当我将 MouseWheel
事件附加到我的 UserControl
或 TextBox
时,如果 TextBox
则不会触发该事件> 是可滚动的。它将滚动文本框而不触发 MouseWheel,我可以使其运行 MouseWheel,然后在执行 e.Cancel
操作后,使 TextBox
不滚动吗?
更新:带有视频和代码
视频
代码
http://www.mediafire.com/?x3o09dz6dr5zoym
public MainWindow()
{
InitializeComponent();
textBox.MouseWheel += (s, e) =>
{
Random rand = new Random();
Debug.WriteLine(rand.NextDouble());
};
}
I found that when I attach a MouseWheel
event to my UserControl
or a TextBox
, it does not trigger if the TextBox
is scrollable. It will scroll the textbox and not trigger MouseWheel, can I make it such that it runs MouseWheel and then after doing something e.Cancel
it so that the TextBox
does not scroll?
UPDATE: With Video & Code
Video
Code
http://www.mediafire.com/?x3o09dz6dr5zoym
public MainWindow()
{
InitializeComponent();
textBox.MouseWheel += (s, e) =>
{
Random rand = new Random();
Debug.WriteLine(rand.NextDouble());
};
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您的意思是 UserControl 上的 MouseWheel 事件不会触发。这是正常的,当消息是多行时,文本框很乐意接受消息。 MouseWheel 事件在设计器中不可见的原因。仅当具有焦点的控件不处理该消息时,父窗口才会看到该消息。
不确定是否应该修复此问题,用户确实希望文本框滚动。但是您可以通过拦截消息使文本框看不到它并将消息传递给父级。将新类添加到您的项目中,粘贴下面所示的代码。编译。从工具箱顶部放下新控件。
I assume you mean that the MouseWheel event on the UserControl won't trigger. That's normal, the TextBox is happy to accept the message when it is multiline. The reason that the MouseWheel event is not visible in the designer. The parent window will only see the message when the control with the focus won't process it.
Not sure if you should fix this, the user would really expect the text box to scroll. But you can by intercepting the message so the text box can't see it and passing the message to the parent. Add a new class to your project, paste the code shown below. Compile. Drop the new control from the top of the toolbox.