简体   繁体   English

在Visual Studio 2010中锁定texbox滚动条

[英]Locking texbox scrollbar in Visual Studio 2010

I've got read-only text box with vertical scroll bar. 我有一个带有垂直滚动条的只读文本框。 Program automatically adds new line text to the text box every 3 seconds. 程序每3秒自动将新行文本添加到文本框中。 After couple of seconds, scroll bar becomes active and I can scroll it, lets say text box is length enough for 4 lines of text, so after 15 second I can scroll it down. 几秒钟后,滚动条变为活动状态,我可以滚动它,假设文本框的长度足以容纳4行文本,因此15秒钟后我可以向下滚动它。
The problem is, that when I scroll down to the bottom/middle/whatever, after 3 seconds (when loop add new line), scroll bar is reset to the start point. 问题是,当我向下滚动到底部/中间/任何地方时,3秒钟后(循环添加新行时),滚动条将重置为起点。 How to lock it, so even if I'm in the middle of the text box and want to read data, the scroll won't get me up? 如何锁定它,所以即使我在文本框的中间想要读取数据,滚动也不会让我起床?

Ok, so my code looks like this (I removed not needed for this post lines): 好的,所以我的代码看起来像这样(我删除了此帖子行不需要的):

public void addToBox(Byte b, bool nextRound)

        {
                   if (nextRound)
                    {
                        textBox1.Text += "\r\n";
                    }
                    textBox1.Text += System.Convert.ToString(b) + " ";
         }

It converting received bytes to string . 它将接收到的bytes转换为string

Try using (This won't lock the scroll bar but remember where it was before the page load): 尝试使用(这不会锁定滚动条,但请记住它在页面加载之前的位置):

this.MaintainScrollPositionOnPostBack = true;

in your page load for the page. 在页面的页面加载中。 This will resolve the issue if you are adding the new line server side. 如果您要添加新的线路服务器端,这将解决该问题。

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

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