[英]How to change text of specific line in multiline textbox in WPF?
I have a multi-line text box in my WPF project, and I want to change the specified line text.我的WPF项目中有一个多行文本框,我想更改指定的行文本。 I used to do this easily in Win form, but there is no Lines option in WPF Text box.我以前在 Win 窗体中很容易做到这一点,但在 WPF 文本框中没有 Lines 选项。 For example, I used to do this in Windows Form:比如我以前在 Windows 表格中是这样做的:
Dim lines As String() = VTextBox1.Lines
lines(Specific Line Number) = "This is a test."
VTextBox1.Lines = lines
But this piece of cod, not working in WPF textbox.但是这条鳕鱼,在 WPF 文本框中不起作用。
Do I have any chance that I do this in the WPF textbox?我有机会在 WPF 文本框中执行此操作吗?
I have no idea how to do that.我不知道该怎么做。
Do it "manually" by manipulating the string yourself:通过自己操作字符串来“手动”执行此操作:
Dim lines As String() = VTextBox1.Text.Split(vbLf)
Dim lineNumber As Integer = 5
If lines.Length > lineNumber Then
lines(lineNumber) = "This is a test."
VTextBox1.Text = String.Join(vbLf, lines)
End If
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.