Reputation: 97
So I am trying to put together a simple add in for outlook which will read email headers. Getting the headers of the email is trivial enough and I have made a windows form with a RichTextBox in order to show the header (currently I am just pushing the full raw headers in, in the future I'd like to format them and make them a bit easier to read, highlight the more important parts etc, hence the RichTextBox).
The problem I am having is that once I set the textbox.Rtf, it loses the natural new lines which are in the headers, which makes them a mess. If I do textbox.Text, they have the linebreaks so they are much nicer to read.
I've tried a few different things in order to try and force the new lines to show (by using \line and \par for example) but it never seems to come through once I use .Rtf.
Public Class showHeaders
Public Shared Sub MyMsg(msg As String)
Dim MsgUserForm1 As New MsgUserForm
With MsgUserForm1
MsgUserForm1.Text = "Email headers:"
.RichTextBox1.Text = msg
.RichTextBox1.Rtf = .RichTextBox1.Text
.Show()
Dim sSaveFolder As String = "C:\headers\"
.RichTextBox1.SaveFile(sSaveFolder & "Headers.txt")
End With
End Sub
Private Shared Function parseHeaders(inputHeader As String) As String
inputHeader = inputHeader.Replace("\r\n", "\line")
inputHeader = inputHeader.Replace("\n", "\line")
inputHeader = inputHeader.Replace("Received:", "\b Received:\b0")
inputHeader = "{\rtf1\ansi " + inputHeader + "}"
Return inputHeader
End Function
End Class
Any help would be welcome as I don't understand why RichTextBox is behaving the way it is.
Upvotes: 0
Views: 39
Reputation: 6923
Vb.net doesn't allow you to use \
to escape the \r\n
or \n
characters to to represent the respective Chr(13) and Char(10) characters
Instead you need to do this.
inputHeader = inputHeader.Replace(VbNewLine, "\line")
inputHeader = inputHeader.Replace(VbLF, "\line")
Alternately you can use Control.Chars.CrLf
and Control.Chars.Lf
Upvotes: 1