VB RichTextBox: bestanden openen / vet

V. Ik heb problemen met de RichtextBox in Visual Basic 2008. Ik probeer bestanden te openen met RichTextBox1.LoadFile(bestandsnaam), mùaar er gebeurt niets. En ik probeer tekst in vet te zetten met RichTextBox1.SelectionFont.Bold =Not RichTextBox1.SelectionFont.Bold, maar krijg de melding dat Bold ReadOnly is.

A. Als je een bestand wil openen, moet je eerst weten welk soort bestand dat is. Check de extensie met een functie:

If extensie(OpenFileDialog1.FileName) = “txt” Then RichTextBox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText)
If extensie(OpenFileDialog1.FileName) = “rtf” Then RichTextBox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.RichText)

Public Function extensie(ByVal pad As String) As String
Return LCase(Mid(pad, Len(pad) – 2, 3))
End Function

Om vet om te keren, moet je een object Font maken:

If richTextBox1.SelectionFont IsNot Nothing Then
Dim currentFont As System.Drawing.Font = richTextBox1.SelectionFont
Dim newFontStyle As System.Drawing.FontStyle

If richTextBox1.SelectionFont.Bold = True Then
newFontStyle = FontStyle.Regular
Else
newFontStyle = FontStyle.Bold
End If

richTextBox1.SelectionFont = New Font( _
currentFont.FontFamily, _
currentFont.Size, _
newFontStyle _
)
End If

Â