RichTextBox Data showing markup tags

zekeman

Well-known member
Joined
May 23, 2006
Messages
224
Programming Experience
10+
My VB6.0 app got user input via a RTB and then wrote the RTB data to

a MS-Jet DB upon request. I could later read the DB and reload the

RTB with the user input data.


I have now converted my app to VB.Net and when I load the RTB with

same old data read from the MS-Jet DB, the data shows up but

it also shows the RTB markup tags (or whatever they are tags).

Question 1:
Has something changed in the way RTB work?

Question 2:
Any suggestions on where and how to begin to fix this?

Thanks
 
To make myself more clear, I am loading the RichTextBox value from

a database field using the statement:

RichTextBox1.SelectedText = .Fields("Notes").Value

and the 'Notes' is a 'Memo' type field.

Thanks
 
Take .SelectedRtf (or .Rtf) properties if you want to insert Rtf coded text rather than plain text.
 
Ok John , You've been very helpful to me so hopefully you can help me again. I've decided to view my customer records in an RTF formated box.

I'm constructing my RichTextBox.text String as follows:

txtRichTextBox.Text =​
"Customer's Name(s): "
txtRichTextBox.Text = txtRichTextBox.Text & txtLastName1.Text & ", " & txtFirstName1.Text & " " & txtMiddleInitial1.Text & "." & Chr(13)
If txtLastName2.Text <> "" Then
txtRichTextBox.Text = txtRichTextBox.Text & Space(33) & txtLastName2.Text &​
", " & _
txtFirstName2.Text &
" " & txtMiddleInitial2.Text & "." & Chr(13)
End If
txtRichTextBox.Text = txtRichTextBox.Text & Chr(13) &​
"Current Address: " & txtCurrentStreet.Text & Space(30) & _
"Future Address: " & txtFutureStreet.Text & Chr(13) & Space(27) & _
txtCurrentCity.Text &
", " & txtCurrentState.Text & ", " & txtCurrentZipCode.Text & _
Space(50) & txtFutureCity.Text &
", " & txtFutureState.Text & ", " & txtFutureZipCode.Text & _
Chr(13) & Chr(13) &
"Current County: " & txtCurrentCounty.Text & Space(45) & "Future County: " & _
txtFutureCounty.Text & Chr(13)

It's Displaying my Information wonderfully. I however wanted to be able to have more control such as tabbed spaces and fixed fields with the smooth print display of using RTF. My problem is I can't seem to figure out how to use the formatting tags.
I'd like my topics like Current Address: for example to be in blue and the actual information in black. I might even want to bold somethings but not everything in constructing this.

Since this information will change I cannot create a file in Wordpad for example and save it as .RTF to be loaded into the control.

So how can I incorporate the formatting tags.

The following doesn't work, I tried but I'm not grasping the conscept I guess.

txtRichTextBox.text = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
{\colortbl ;\red0\green0\blue255;}
{\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\cf1\f0\fs20 Test\cf0\par
}"
:confused:

 
Programming the rtf format directly is difficult. Even if you download the full 200 pages Rich Text Format specification from MS (and read it) I think this would give you a little struggle. But go ahead and learn it if you wish, you're absolutely not the first to do that, they are just rules like anything else programming.

The other alternative is the RichTextBox class properties and methods that begin with "Select...", here is the member list from documentation online MSDN http://msdn2.microsoft.com/en-US/library/system.windows.forms.richtextbox_members.aspx

You could calculate position and length while appending the text, make the selection and apply the formatting to the selection, then continue append. (Or store all these locations+length+formatting and select/format afterwards)
 
Well John in the midst of my confusion while I slowly contemplated committing ritual suicide. I decided to use the WebBrowser control in 2005 to display the information. Since I have a much stronger concept of using the HTML Tags inside my String I can control the displayment of the information more to my liking including Tables. I clipped a bit of my routine here to show how much simpler this was then trying to use the now very complicated RTF.



Info =​
"<table border=" & "0" & "width=" & "100%" & "id=" & "table1" & "cellspacing=" & "1" & ">" & _

"<tr><td width=" & "100" & "><font color = " & "#0000FF" & " size=" & "2" & ">Customers Name:</td>" & "<td><Font size=" & "2" & ">" & txtLastName1.Text & ", " & txtFirstName1.Text & " " & txtMiddleInitial1.Text & "." & "</font></td></tr>"

If txtLastName2.Text <> ""Then
Info = Info &​
"<tr><td width=" & "100" & "></td><td><font size=" & "2>" & txtLastName2.Text & ", " & _
txtFirstName2.Text & " " & txtMiddleInitial2.Text & ".</font></td><td width=" & "174" & "></td></tr>"
EndIf


Info = Info & "<tr><td width=" & "100" & "></td><td><font size=" & "2></font></td><td width=" & "174" & "></td></tr>"
Info = Info & "</table><table border=" & "0" & "width=" & "100%" & "id=" & "table2" & "cellspacing=" & "1" & ">" & _
"<tr><td width=" & "100" & "><font color = " & "#0000FF" & " size=" & "2" & ">" & _
"Current Address:</font></td>" & "<td width=" & "235" & ">" & "<font size =" & "2>" & txtCurrentStreet.Text & "</font></td>" & "<td><p align=" & _
"right" & "><font color = " & "#0000FF" & " size=" & "2" & ">Future Address:</td>" & "<td width=" & "175" & ">" & "<font size =" & "2>" & txtFutureStreet.Text & _
"</tr>" & "<tr><td width=" & "100" & "></td><td width=" & "235" & "><font size =" & "2>" & txtCurrentCity.Text & ", " & txtCurrentState.Text & ", " & txtCurrentZipCode.Text & "</td>" & _
"</font><td></td><td width=" & "175" & ">" & "<font size =" & "2>" & txtFutureCity.Text & ", " & txtFutureState.Text & ", " & txtFutureZipCode.Text & "</font></td></tr>" & _
"<tr><td width=" & "100" & "></td><td width=" & "235" & "><font size =" & "2" & ">" & txtCurrentCounty.Text & " County" & "</td><td width=" & "100" & "></td><td width=" & _
"235" & "><font size =" & "2" & ">" & txtFutureCounty.Text & " County" & "</td></tr>"


WebBrowser.DocumentText = Info

:D

P.S. I was thinking that in doing it this way it might also prepare the information to be printed more easily.
 

Latest posts

Back
Top