這個問題是關於擴展控制:FastColoredTextbox這裏:http://www.codeproject.com/Articles/161871/Fast-Colored-TextBox-for-syntax-highlightingFastColoredTextbox問題滾動文字和定位插入符號
我試圖自動向下滾動文本,並把文本光標的最後一個字符附加的文本(我認爲文本屬性的總長度)。
文本滾動問題
這是工作的自動文本滾動:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
FastColoredTextBox1.Text = str
FastColoredTextBox1.ScrollLeft()
FastColoredTextBox1.Navigate(FastColoredTextBox1.Lines.Count - 1)
End Sub
...但我想讓它更通用,這不工作:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
FastColoredTextBox1.Text = str
End Sub
Private Sub FastColoredTextBox1_TextChanged(sender As Object, e As FastColoredTextBoxNS.TextChangedEventArgs) Handles FastColoredTextBox1.TextChanged
sender.ScrollLeft()
sender.Navigate(FastColoredTextBox1.Lines.Count - 1)
End Sub
任何錯誤或異常,只是不會工作,文本不滾動像在第一個例子。
鍵盤的光標位置問題
關於文本光標,我已經試過,但沒有工作過:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
FastColoredTextBox1.Text = str
FastColoredTextBox1.SelectionStart = FastColoredTextBox1.Text.Length
End Sub
任何錯誤或異常,只是不工作。
UPDATE
試過@ebyrob解決方案,但不起作用,它不會滾動下來。
Imports FastColoredTextBoxNS
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim str As String = String.Empty
For x As Int32 = 1 To 1000 : str += vbNewLine & x : Next
FastColoredTextBox1.Text = str
End Sub
Private Sub FastColoredTextBox1_TextChanged(sender As Object, e As TextChangedEventArgs) Handles FastColoredTextBox1.TextChanged
GoEnd()
End Sub
Public Sub GoEnd()
If FastColoredTextBox1.Lines.Count > 0 Then
FastColoredTextBox1.Selection.Start = New Place(FastColoredTextBox1.Lines(FastColoredTextBox1.Lines.Count - 1).Count, FastColoredTextBox1.Lines.Count - 1)
Else
FastColoredTextBox1.Selection.Start = New Place(0, 0)
End If
FastColoredTextBox1.DoCaretVisible()
End Sub
End Class
更新兩個
的@ebyrob代碼工作只有當我追加文本後稱之爲 「GoEnd」 一如既往,像這樣的例子:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim str As String = String.Empty
For x As Int32 = 1 To 1000 : str += vbNewLine & x : Next
FastColoredTextBox1.Text = str
GoEnd()
End Sub
這是相同的我評論過的第一個問題(TextChanged事件沒有按預期工作)的問題,我需要使其效率和通用,我認爲控件的「TextChanged」事件將是正確的事件把「GoEnd()」,但肯定不是。
我不想讓這個永遠
1. Add text
2. Call GoEnd
3. Add more text
4. Call again GoEnd
我wan't把「GoEnd」中贏得成功,當文本更改爲簡化事物的事件:
1. add text
2. add more text
UPDATE三
所有的問題都解決了,只是改變了事件名稱:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim mytext As String = String.Empty
For x As Int32 = 1 To 1000 : mytext += vbNewLine & x : Next
FastColoredTextBox1.Text += mytext
FastColoredTextBox1.Focus()
End Sub
Private Sub FastColoredTextBox1_TextChanged(sender As Object, e As FastColoredTextBoxNS.TextChangedEventArgs) _
Handles FastColoredTextBox1.TextChangedDelayed
sender.ScrollLeft()
sender.Navigate(sender.Lines.Count - 1)
FastColoredTextBox1.SelectionStart = FastColoredTextBox1.Text.Length
End Sub
End Class
我很難理解你的問題究竟是什麼以及你想達到的目標......你能詳細闡述一下嗎? –
「不起作用」是什麼意思?這是否僅僅是一個編譯錯誤,因爲沒有將發送者轉換爲FastColoredTextBox?也不應該最後一個例子是'.SelectionStart = FastColoredTextBox1.Text.Length - 1'? – 2013-05-31 13:03:14
你將不得不施放這個'sender'對象。你需要記錄這個FastColoredTextBox組件是什麼。 – LarsTech