我有自己的自定义 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
关于.net - 多行文本框中的当前行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/539164/