CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  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.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured