问题描述
我的应用程序中有一个多行文本框,当我中键单击向上或向下滚动时,它不起作用.
i have a multiline textbox in my app and when i middle-click to scroll up or down, it doesn't work.
它在记事本中有效,但在我的文本框中无效.有人知道为什么吗?或者,是否可以在单击中间按钮时以编程方式开始向所需方向滚动?
It works in Notepad, but not in my textbox. Does anybody know why? or, if it is possible to programatically begin scrolling in the desired direction when the middle-button's clicked?
推荐答案
要让鼠标滚轮滚动工作,请创建您自己的继承 TextBox 的自定义 TextBox 类.
To get the mouse wheel scroll thing to work, make your own custom TextBox class that inherits TextBox.
重写 WndProc 方法.
Override the WndProc method.
查看消息类型.
对于消息类型 0x207 (WM_MBUTTONDOWN),调用 DefWndProc(ref m);对于任何其他消息类型,调用 base.WndProc(ref m);
For Message type 0x207 (WM_MBUTTONDOWN), call DefWndProc(ref m); For any other message type, call base.WndProc(ref m);
然后你的文本框会有中间按钮滚动.
Then your text box will have middle button scroll.
通常 Windows.Forms 会覆盖文本框的内置中间按钮功能,因此控件可以在中间按钮上有一个 MouseDown 事件,但这也会禁用固有的滚动功能.返回调用默认窗口处理程序,文本框恢复其滚动功能.
Normally Windows.Forms overrides the built-in middle button feature of the textbox so the control can have a MouseDown event on the middle button, but that also disables the innate scroll feature. Go back to calling the default window handler, and the textbox gets its scroll feature back.
这篇关于文本框中的中间按钮滚动的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!