简体   繁体   English

多行文本框中的当前行

[英]Current line in a multiline textbox

I've got my own custom TextBox control, wich inherits from System.Windows.Forms.TextBox.我有我自己的自定义 TextBox 控件,它继承自 System.Windows.Forms.TextBox。 I've overrided OnKeyDown method, because I want to select the previous or next control if the user press either up or down keys.我已经覆盖了 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

In a multiline textbox, what is the better way to know if I'm in the first or last line?在多行文本框中,知道我是在第一行还是最后一行的更好方法是什么?

Thanks very much非常感谢

It's rough, but it should do the job.这很粗糙,但它应该可以完成工作。

    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