[RESOLVED] Format the text contained into a RichTextBox
Hi folks :)
It's been long time from the last time I asked for your help and now I'm here because I need it again :(
I am trying to format a text contained into a RichTextBox exactly like the text below:
FIRM NAME of Surname Name
Address - ZIP City
Phone: Number Fax: Number
E-mail: Address Web site: URL
VAT number: VAT number
Then, each line must be centered into the control.
Til now I wrote this code, that obviously doesn't work:
Code:
Private Sub StampHeading()
Dim Buff As String
With rtxIssuer(1)
Buff = (Issuer.Firm & " di " & Issuer.Surname & " " & Issuer.Name & vbNullChar)
.Text = Buff
.SelStart = 0:
.SelLength = Len(Buff)
.SelBold = True
Buff = (Issuer.Address & " - " & Issuer.ZIP & " " & Issuer.City & vbNullChar)
.Text = (.Text & Buff)
.SelStart = Len(.Text) - Len(Buff)
.SelLength = Len(Buff)
.SelColor = vbGray
Buff = Trim(IIf(Len(Issuer.Phone) > 0, "Telefono: " & Issuer.Phone, "") & Space(5) & IIf(Len(Issuer.Fax) > 0, "Fax: " & Issuer.Fax, ""))
If Len(Buff) > 0 Then Buff = Buff & vbNullChar
.Text = (.Text & Buff)
If InStr(1, .Text, "Telefono: ") > 0 Then
.SelStart = .Find("Telefono: ", 0, Len(.Text))
.SelLength = Len("Telefono: ")
.SelBold = True
End If
.SelStart = 0
.SelLength = Len(.Text)
.SelAlignment = 3 ' Center aligned (or at least I think)
End With
End Sub
The result I got is that the whole text isn't formatted and you still see with the default control's Font and ForeColor property (in my case, I see it all written in Arial [bold; 8 pt; black] )
Help me, please :(
:wave:
Re: Format the text contained into a RichTextBox
I don't see anywhere that you have changed either the font or the forecolor property. "Isn't formatted" doesn't give enough information for me to understand anything more about your problem.
Re: Format the text contained into a RichTextBox
Create the RTF form first, with all the fields in the right place. Then, it's not hard to apply FORMAT commands to the document once you've opened it. I had 4 different RTF's that printed two reports and invoices.
Re: Format the text contained into a RichTextBox
@dglienna:
I don't have ever used RTF files before now, so, I don't know what to do. However, whilst I was waiting for your replies, I found another way to solve my problem using a PictureBox and printing on it what I need to display.
But, thanks.
@BobRodes
Why do you think I've set the SelStart, SelLength and SelColor properties? About the fonts, I don't need to change it: it's enough the Font set for the Control. If you tried the code, you could see that the text was written all in black (the default Control's ForeColor), even though in run-time I called the SelColor property to change the ForeColor to a specific string selected.
Anyway, I solved my own using a PictureBox :)
Thank you all,
bye :wave: