[RESOLVED] Format the text contained into a RichTextBox
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] Format the text contained into a RichTextBox

  1. #1
    Join Date
    Dec 2012
    Posts
    38

    [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
    Last edited by Cereal Killer; April 12th, 2013 at 06:22 AM.

  2. #2
    Join Date
    Apr 2013
    Posts
    2

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,981

    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.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Dec 2012
    Posts
    38

    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
    Last edited by Cereal Killer; April 15th, 2013 at 07:57 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center