Vb.net richtextbox行问题 [英] Vb.net richtextbox lines problem
问题描述
我在Microsoft Word的RTF中有4行文字
第一行文字。
第二行文字。
第三行文字。
第四行文字。
我也有从每行到控制台生成文本的代码:
I have 4 lines of text in RTF from Microsoft Word
First line of text.
Second line of text.
Third line of text.
Fourth line of text.
I have also code for generating text from each line to console:
rtb = New RichTextBox
rtb.Rtf = My.Computer.Clipboard.GetText(TextDataFormat.Rtf)
Dim linesCount As Integer = rtb.Lines.Count
For i = 0 To linesCount - 1
Dim start As Integer = rtb.GetFirstCharIndexFromLine(i)
Dim currLine As Integer = rtb.GetLineFromCharIndex(start)
Dim currLineText As String = rtb.Lines(currLine)
Dim length As Integer = currLineText.Length
rtb.Select(start, length)
Debug.Print(rtb.SelectedText)
Next
还有我的问题。
虽然我使用动态创建的RichTextBox(如上所示)但我得到了怪异的结果
冷杉st行文字。
文字。
第二行
第二行文字
text。
第三行
但是当我使用在Form1上创建的RichTextBox1切换时,我得到了我所期待的。
And there is my issue.
While I use dynamically created RichTextBox (as above) I get weirdo result
First line of text.
text.
Second line of
Second line of text
text.
Third line of
But when I switch using RichTextBox1 created on Form1 I get what I espected.
Form11.RichTextBox1.Rtf = My.Computer.Clipboard.GetText(TextDataFormat.Rtf)
Dim linesCount As Integer = Form11.RichTextBox1.Lines.Count
For i = 0 To linesCount - 1
Dim start As Integer = Form11.RichTextBox1.GetFirstCharIndexFromLine(i)
Dim currLine As Integer = Form11.RichTextBox1.GetLineFromCharIndex(start)
Dim currLineText As String = Form11.RichTextBox1.Lines(currLine)
Dim length As Integer = currLineText.Length
Form11.RichTextBox1.Select(start, length)
Debug.Print(Form11.RichTextBox1.SelectedText)
Next
第一行文字。
第二行文字。
第三行文字。
第四行文本。
任何想法为什么会发生这种情况?我更喜欢在我的场景中使用动态创建的RichTextBox。
我尝试过:
不知道在这里写什么:)
First line of text.
Second line of text.
Third line of text.
Fourth line of text.
Any idea why is this happening? I would prefer to use dynamically created RichTextBox in my scenario.
What I have tried:
Not sure what to write here :)
推荐答案
你没有设置动态创建的RichTextBox的宽度,所以它正在包装文本。尝试将rtb.Width
设置为与RichTextBox1
You haven't set the width of the dynamically created RichTextBox so it is wrapping the text. Try settingrtb.Width
to the same value as in yourRichTextBox1
中的相同值
这篇关于Vb.net richtextbox行问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!