简体   繁体   English

在另一个控件中转动鼠标滚轮时,如何使TextBox滚动?

[英]How can I make a TextBox scroll when the mouse wheel is turned in another control?

I'm making an IRC client where the chat is displayed in a multi-line TextBox control named chatBox. 我正在制作一个IRC客户端,在其中将聊天显示在名为chatBox的多行TextBox控件中。 Below the chat there is a single-line textBox named editBox where the user enters messages. 聊天下方是一个名为editBox的单行文本框,用户可以在其中输入消息。 I want the user to be able to scroll in the chatBox even while the editBox has the focus. 我希望用户即使在editBox具有焦点的情况下也能够在chatBox中滚动。 Is there any way I can do that? 有什么办法可以做到吗?

I've looked at the events for textBox and I can't find anything resembling a scroll event, and I've searched Google for an answer with no success. 我已经查看了textBox的事件,但找不到类似于滚动事件的任何事件,并且我一直在Google搜索中寻找没有成功的答案。

You can't scroll directly, but you can move the cursor. 您不能直接滚动,但可以移动光标。 You can move the cursor to the end of a text box, for example, with textBox.SelectionStart = textBox.Text.Length . 例如,可以使用textBox.SelectionStart = textBox.Text.Length将光标移动到文本框的textBox.SelectionStart = textBox.Text.Length

By manipulating the selection you can emulate scrolling by using textBox.ScrollToCaret() . 通过操纵选择,您可以使用textBox.ScrollToCaret()来模拟滚动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM