繁体   English   中英

多行文本框中的当前行

[英]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.

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