2013-03-23 66 views
0

我有一个滚动条(垂直启用)的文本框。当我写入texbox并且我的文本不能显示在文本框中时,它会启动滚动条功能(这是滚动条的目的),但它不会跟随我。Ibeam不会显示,我应该手动滚动对它来说,这是一件不太容易的事情。我能做些什么来解决这个问题?有没有内置的功能来解决这个问题?
这是如何跟随在滚动条中插入的文本框

 resources.ApplyResources(this.textBox1, "textBox1"); 
     this.tableLayoutPanel1.SetColumnSpan(this.textBox1, 5); 
     this.textBox1.Cursor = System.Windows.Forms.Cursors.IBeam; 
     this.textBox1.HideSelection = false; 
     this.textBox1.Name = "textBox1"; 
     this.textBox1.ReadOnly = true; 

回答

1

可以使用ScrollToCaret方法。将一个TextChanged事件处理程序附加到文本框,以便每当文本更改并滚动到插入符的位置时调用它。

//attach handler 
textBox1.TextChanged += new EventHandler(textBox1_TextChanged); 

private void textBox1_TextChanged(object sender, EventArgs e) 
{ 
    //move the caret to the end to ensure it scrolls right to the bottom 
    textBox1.SelectionStart = textBox1.Text.Length; 

    //scroll to the caret 
    textBox1.ScrollToCaret(); 
} 
0

在keydown事件使用

this.textBox1.Select(this.textBox1.Text.Length-1, 0) 
相关问题