如何将label / textbox / richtextbox与列表框滚动条同步 [英] How to sync label/textbox/richtextbox with listbox scrollbar

查看:100
本文介绍了如何将label / textbox / richtextbox与列表框滚动条同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法可以将滚动标签,TextBox或RichTextBox与ListBox ScrollBar同步?



ScrollBar应仅对ListBox和(Label,TextBox或RichTextBox不应该有任何scollbar)



我已经提到过Label,TextBox或RichTextBox,任何人都可以为我工作,无论哪个与ListBox同步滚动兼容。



我尝试了什么:



我试过2个RichTextBox同步但不是我正在寻找的东西,虽然,我也试过2个ListBox Scroll,我已经隐藏了1个ScrollBar Scroller,但这很慢而且没有一起滚动,有几毫秒的延迟。

解决方案

我得到了一个ListBox和RichTextBox,但只有一种方式...意思是滚动RTB将滚动LB而不是相反

这是代码...把它放在RTB的VScroll功能中

  Dim  lineNumber  As  整数 =  0  

lineNumber是一个全局变量...

  Dim  firstVisibleChar  As   Integer  = RichTextBox1.GetCharIndexFromPosition( New  Point( 0  0 ))
lineNumber = RichTextBox1.GetLineFromCharIndex(firstVisibleChar )
ListBox1.TopIndex = lineNumber



我知道我们可以更多地简化这段代码,但我已经做了一点,所以任何人都可以轻松理解它...


Is there a way where we can Sync scroll Label, TextBox or RichTextBox with ListBox ScrollBar?

ScrollBar should be visible only for ListBox and (Label, TextBox or RichTextBox should not have any scollbar)

I've mentioned Label, TextBox or RichTextBox, anyone could work for me, whichever is compatible to sync scroll with ListBox.

What I have tried:

I tried 2 RichTextBox sync but thats not what I'm looking for, though, I've also tried 2 ListBox Scroll and I've Hide 1 ScrollBar Scroller but that is slow and not scrolling together, there's a delay of some milliseconds.

解决方案

I got this working for a ListBox and a RichTextBox but only one way... Meaning that scrolling the RTB will scroll the LB but not the opposite
Here is the code... Put it in the VScroll function of the RTB

Dim lineNumber As Integer = 0

lineNumber is a global variable...

Dim firstVisibleChar As Integer = RichTextBox1.GetCharIndexFromPosition(New Point(0, 0))
lineNumber = RichTextBox1.GetLineFromCharIndex(firstVisibleChar)
ListBox1.TopIndex = lineNumber


I know we can simplify this code more, but I've made it a bit longer so that anyone can easily understand it...


这篇关于如何将label / textbox / richtextbox与列表框滚动条同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆