我正在尝试将.rtf打开到富文本框
每次打开文件时,都会将其放入Rich Text Box:
http://pastebin.com/jwYwds9y [显示原始RTF]
这是我打开的代码:
Public Sub openFile()
Dim ofd As New OpenFileDialog
ofd.Filter = fileFilter
ofd.FileName = ""
Select Case ofd.ShowDialog()
Case DialogResult.OK
loadFile(ofd.FileName)
End Select
End Sub
Public Sub loadFile(ByVal file As String)
Try
fileName = file
setText(IO.File.ReadAllText(file))
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Sub setText(ByVal value As String)
Dim t As RichTextBox = tabH.SelectedTab.Controls.OfType(Of RichTextBox)().First()
t.Text = value
End Sub
我有一个标签控件,没有主文本框,当应用程序运行时,它使用代码添加第一个标签。代码:
Public Sub newFile()
Dim t As New TabPage
Dim p As New RichTextBox
t.Text = "Untitled"
p.Parent = t
p.Dock = DockStyle.Fill
tabH.TabPages.Add(t)
t.Visible = True
AddHandler p.KeyDown, Sub(sn As Object, e As KeyEventArgs) makeChanged()
End Sub
答案 0 :(得分:2)
您需要使用t.Rtf = value
。
设置.Text
属性逐字输入数据,而设置Rtf
property会导致它将数据解析为RTF。
您还可以考虑使用RichTextBox.LoadFile Method。