C# 中滚动条的两个问题
我讨厌两个 richTextBox
。
我有两个问题:
无论我如何定义滚动条 - 它都不会出现。如果我写的内容超过了行的长度 - 光标会转到下面的行 - 我希望所有内容都写在同一行中,并且用户可以使用滚动条从右向左移动。
我想要一个滚动条来控制两个富文本框。 一个水平的两个,一个垂直的两个。
I hate two richTextBoxs
.
I have two problems:
no matter how I define the scroll bar - it doesn't apear. if I write more than the length of the line - the cursor goes to the line below - I want everything to be writen in the same row and the user could move right-left with the scroll bar.
I want one scroll bar to control both richtextboxes.
one horizontal for both, and one vertical for both.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MultiLine如果您只需要一行,请将
属性设置为 false(RichTextBox 的默认值为 true),否则设置WordWrap
属性设置为 false(这也默认为 true)。HScroll
和 每个 RichTextBox 的VScroll
事件,并在事件处理程序中以相同的量滚动其他文本框。但不确定这有多容易......MultiLine
property to false (the default is true for RichTextBoxes) if you just want one line, or else set theWordWrap
property to false (this also defaults to true).HScroll
andVScroll
events of each RichTextBox, and in the event handlers scroll the other textbox by the same amount. Not sure how easy this would be, though...解决第二个问题的最佳方法是使用 GetScrollInfo 和 SetScrollInfo。我认为您应该能够处理
HScroll
和VScroll
事件,当它们触发时,您必须在第二个 RichTextBox 中设置新的 ScrollInfo。您还需要 WM_SendMessage 来完成这项工作。 (所有都可以通过导入User32.dll使用)
通常要做的工作:
当用户滚动(Scrollevents)时获得通知,并将新的ScrollInfo设置为第二个RichTextBox。设置 ScrollInfo 后,您需要向滚动条/滚动控件发送一条消息。
首先,您需要“自己的”
SCROLLINFO struct
然后在第一个 TextBox 中的 ScrollingEvent 处获取 Scrollinfo:(
其中 _si 是您的 SCROLLINFO 实例)。然后将消息发送到滚动条,
其中
HANDLE
是必须滚动的 RichTextBox 的句柄 - 您可以随时使用该句柄您应该真正看看 http://msdn.microsoft.com/en-us/library/bb787537%28VS. 85%29.aspx 和 http:// /msdn.microsoft.com/en-us/library/ms644950%28VS.85%29.aspx
pinvoke.net 上也有一些很好的示例(例如 GetScrollInfo)
Best way to solve your second Problem is to use GetScrollInfo and SetScrollInfo. I think you should be able to handle the
HScroll
andVScroll
events, when they fire you'll have to set the new ScrollInfo in the second RichTextBox.You'll need WM_SendMessage too for this job. (All usuable with imports of User32.dll)
Usual work to do:
Getting informed when the user scrolls (Scrollevents), and setting the new ScrollInfo to the second RichTextBox. After setting the ScrollInfo you'll need to send a Message to the Scrollbar / Control to Scroll.
First of all you need your "own"
SCROLLINFO struct
Then get the Scrollinfo at ScrollingEvent in the first TextBox:
(where _si is your SCROLLINFO-instance). Then send the message to the scrollbar
Where
HANDLE
is the Handle of your RichTextBox that has to be scrolled - you can get the handle at anytime usingYou should really have a look at http://msdn.microsoft.com/en-us/library/bb787537%28VS.85%29.aspx and http://msdn.microsoft.com/en-us/library/ms644950%28VS.85%29.aspx
There are also some good examples at pinvoke.net (for example GetScrollInfo)