2016-09-18 72 views
0

我試圖打開一個.RTF到一個格式文本框RTF不開放到RichTextBox中正確

每次我打開它把這個到格式文本框的文件:

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 
+2

你試過't.Rtf = value'嗎? –

+1

@AndrewMorton你應該寫這個答案,因爲這很可能是解決方案。 –

+1

@VisualVincent有時需要我花時間思考我可以如何有效地填充一個非常簡短的答案,以增加一些價值。 –

回答