middle-button scrolly thing in textbox

2019-02-25 06:31发布

问题:

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?

回答1:

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.



回答2:

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