gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 07:09:57 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com