Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

All text bolded when adding text to RichTextBox 1

Status
Not open for further replies.

RobHVB6Sql

Programmer
May 20, 2002
77
AU
Phew, been looking at posts re this here and my head is about explode.

First time dealing with RichTextBoxes.
When I add text to a RichTextBox all text is made bold.

How can I add text to the end of the RichTextBox before I print it with specific formats?

Do I:
1) Format the text and then insert it. But then how to return the original text to its previous state.

2) Add it and then format ir.

3) Should I use .TextRTF or .text to insert?

Code:
'rtbHelp is a richtext box
'strPrintFooter is a string variable

strPrintFooter = "Printed: " & Format(Now, StdDateFormat) + vbLf + _
"Printed By: " & CurrUser.FirstName & " " & UCase(CurrUser.Surname) & " (" & CurrUser.UserID & ")"
rtbHelp.Text = rtbHelp.Text & strPrintFooter



Rob Hasard
Data Manager -Genetic Services
(VB6 /SQL 7.0)
 
Hi,

The command you use to toggle bold on/off is:

Code:
rtbHelp.SelBold = false ' to turn it off

When inserting data into the RTF control I always use the TextRTF property as opposed to just the text one.

If you still have problems then try loading your text file into word to see if the formatting exists prior to inserting it into your text box....alernatively try the following:

Code:
rtbHelp.SelStart = 0
rtbHelp.SelLength = Len (rtbHelp.Text)
rtbHelp.SelBold = false

Hope this helps


Andrew
 
Thanks Andrew, I'm very close now.

The RichTextBox contents (text or textRTF) are changed to bold or not bold, when I think according to my code ONLY the selection (ie the strPrintFooter variable) should be bolded.

Can you see the error?

Code:
'Add print details to the rich text box (these will be printed)
strPrintFooter = vbLf + vbLf + _
"Printed: " & Format(Now, StdDateFormat) + _
vbLf + _
"Printed By: " & CurrUser.FirstName & " " & UCase(CurrUser.Surname) & " (" & CurrUser.UserID & ")"

'insert footer information text
rtbHelp.TextRTF = rtbHelp.Text & strPrintFooter 'inserted, but all text unbolded

'Select the footer information
rtbHelp.SelStart = Len(rtbHelp.Text) - Len(strPrintFooter)
rtbHelp.SelLength = Len(strPrintFooter)

'format footer information
rtbHelp.SelAlignment = rtfLeft 'left justify
rtbHelp.SelBold = True 'bold *** error here

'reset the cursor
rtbHelp.SelStart = 0
rtbHelp.SelLength = 0


Rob Hasard
Data Manager -Genetic Services
(VB6 /SQL 7.0)
 
Your error is assuming that SelBold changes existing text. It only changes SelText as it is changed

rtbHelp.SelStart = Len(rtbHelp.Text) - Len(strPrintFooter)
rtbHelp.SelLength = Len(strPrintFooter)
'format footer information
rtbHelp.SelAlignment = rtfLeft 'left justify
rtbHelp.SelBold = True 'bold *** error here
''' TRY
rtbHelp.SelText = rtbHelp.SelText



Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Sorry the last comment had no effect, the code is already doing this. I can format the footer as I like, although the original text in the richtext box (rtbHelp.Text) is all set to non-bold at the point of adding to /appending to the rich text box ***, can anyone stop this?

The code:
'rtbHelp is a richtext box
'strPrintFooter is a string variable

rtbHelp.TextRTF = rtbHelp.Text & strPrintFooter
'all original text (rtbHelp.Text) unbolded at this point, formatting lost ***

'Select the footer information
rtbHelp.SelStart = Len(rtbHelp.Text) - Len(strPrintFooter)
rtbHelp.SelLength = Len(strPrintFooter)
'rtbHelp.SelText = rtbHelp.SelText 'had no affect, not needed

'format footer information
rtbHelp.SelAlignment = rtfLeft 'left justify
rtbHelp.SelBold = True 'bold

'reset the cursor
rtbHelp.SelStart = 0
rtbHelp.SelLength = 0

Thanks in advance

Rob Hasard
Data Manager -Genetic Services
(VB6 /SQL 7.0)
 
rtbHelp.SelStart = Len(rtbHelp.Text)
rtbHelp.SelAlignment = rtfLeft
rtbHelp.SelBold = True
rtbHelp.SelText = strPrintFooter
rtbHelp.SelStart = 0
 
Yes yes yes.

It looks as though I was not selecting the end of the text before inserting.

Thanks strongm :)

Rob Hasard
Data Manager -Genetic Services
(VB6 /SQL 7.0)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top