middle-button scrolly thing in textbox

2019-02-25 06:04发布

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?

2条回答
别忘想泡老子
2楼-- · 2019-02-25 07:02

To get the mouse wheel scroll thing to work, make your own custom TextBox class that inherits TextBox.

Override the WndProc method.

Look at the message type.

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.

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.

查看更多
我命由我不由天
3楼-- · 2019-02-25 07:08

Do you have the ScrollBars property set to Vertical or Both?
For me it's not working only when ScrollBars = NoneorHorizontal

查看更多
登录 后发表回答