.net - 多行文本框中的当前行

标签 .net user-controls

我有自己的自定义 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/

相关文章:

.net - 轻松创建/更新 Office Open XML 图表(首选 PowerPoint)

c# - 用户控制开关

c# - ASP.NET 用户控件 : can't initialize a user control property using Eval ("...")

asp.net - 使用 web.config 停止目录中的热链接

c# - 如何在 WebApi 请求中获取 Controller 名称?

c# - 返回 IList 与 List 或 IEnumerable 与 List<Class> 之间有什么区别。我想知道返回哪个更好

.net - 强制自定义 WPF 控件正确调整大小

wpf - 更改用户控件的颜色

c# - 确定自定义 winforms 控件的设计时上下文

javascript - Jquery 不能在 .net 项目中工作