[英]Current line in a multiline textbox
我有我自己的自定義 TextBox 控件,它繼承自 System.Windows.Forms.TextBox。 我已經覆蓋了 OnKeyDown 方法,因為如果用戶按下向上或向下鍵,我想選擇上一個或下一個控件。
Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
MyBase.OnKeyDown(e)
If e.KeyCode = Keys.Up Then
If Not Multiline Then
Me.FindForm().SelectNextControl(Me, False, True, True, True)
Else
'TODO: If the current line is the first one, select the previous control
End If
ElseIf e.KeyCode = Keys.Down Then
If Not Multiline Then
Me.FindForm().SelectNextControl(Me, True, True, True, True)
Else
'TODO: If the current line is the last one, select the next control
End If
End If
End Sub
在多行文本框中,知道我是在第一行還是最后一行的更好方法是什么?
非常感謝
這很粗糙,但它應該可以完成工作。
If Me.Text.IndexOf(Environment.NewLine, 0, Me.SelectionStart) = -1 Then
'no new lines before
End If
If Me.Text.IndexOf(Environment.NewLine, SelectionStart) = -1 Then
'no new lines after
End If
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.