Solved

RTF Box as Report Viewer

Posted on 2002-04-23
13
1,399 Views
Last Modified: 2008-03-10
Hello,
     Can I use rich text box to display and print reports. My problem is I don't know how to add text to RTF Box at runtime using different fonts and colors at a particular line.

     For example, If I do something like this:
       
     rtf.Font.Size = 15
        rtf.Text = "Hello"
        rtf.Font.Name = "Arial"
        rtf.Font.Size = 20
        rtf.Text = rtf.Text & " How"
     
     Then both words are displayed using Size 20 and font arial. But I wanted that only second word should be of size 20 and font "Arial".
     
     Also If I want to move to a particular line and then move to a column n and start writing text at column n. So is there any way to do it?
0
Comment
Question by:Sukhwinder Singh
  • 4
  • 4
  • 3
  • +2
13 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6964550
You need to use selfont and all properties that begins with sel....
0
 
LVL 3

Accepted Solution

by:
n_narayanan earned 50 total points
ID: 6964723
Check this,

    RichTextBox1.Text = "text stuff*color me blue*textstuff*color me blue*text stuff*blue*text*blue*text"
   
    Marcfindit = "*"
    Lengther = Len(Marcfindit)
    TotalLength = Len(RichTextBox1.Text)
   
   
    Start = 0
    Do Until Start >= TotalLength
      foundpos1 = RichTextBox1.Find(Marcfindit, Start, TotalLength, Text)
      If foundpos1 = -1 Then Exit Do
      If foundpos1 <> -1 Then 'asterisk found
          foundpos2 = RichTextBox1.Find(Marcfindit, foundpos1 + 1, TotalLength, Text)
            If foundpos2 = -1 Then Exit Do
            If foundpos2 <> -1 Then

                 RichTextBox1.SelStart = foundpos1
                 RichTextBox1.SelLength = foundpos2 - foundpos1 + 1
                 RichTextBox1.SelBold = True
                 RichTextBox1.SelColor = RGB(0, 0, 255)
               
                 Start = foundpos2 + 1  ' start looking here
            End If
         End If
    Loop
     
      RichTextBox1.SelStart = 0
      RichTextBox1.SelBold = False
      RichTextBox1.SelColor = RGB(0, 0, 0)

The above code can be found at http://www.freevbcode.com/ShowCode.Asp?ID=2519

Narayanan.
0
 

Author Comment

by:Sukhwinder Singh
ID: 6967125
Yes It works but * is visible. What else can be used in its place; space? Also you have added all text before changing font color etc. I want to retrieve record from a database and then display information contained in a record's fields one by one and line by line. If I use this method then for every field/row I add, I have to add a new invisible special character to identify that field/row which may not be possible. Also If there many lines then It wont look great on slow computers if text attributes change after displaying all text.

For example, If want to create a report to display employee records and I want that employee name should be Bold and centred, other fields should use different color, indentation etc. So, if I don't use this special character because it may not be used if there are 30-35 fields, I need a way to go a particular row and particular column and then write text there and change its colors etc. and then go to next row, write other information change text attributes and so on.

So main problem is going to a particular line/column, add more text and then change font etc of added text only.

Is there any way to achieve this?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6967205
0
 

Author Comment

by:Sukhwinder Singh
ID: 6974074
Yes it was very close to my requirement. But I cannot add text to rtf directly but I have to retrieve records from database and then display them one field at a time. So I need a way where when I add more text, formatting of old text of rtf box doesn't change.

For example if I do rtf.text = rtf.text+"Hello" than I don't want that properties of text (fonts, colors etc)which is already there in rtf.text doesn't change.

Changing text attribute of text when text is entered directly into rtf box is simple.
But how can I achieve it when entering text through code at runtime?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7660821
Hi indianmunda,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept n_narayanan's comment(s) as an answer.

indianmunda, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7660833
Hi indianmunda,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept n_narayanan's comment(s) as an answer.

indianmunda, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Author Comment

by:Sukhwinder Singh
ID: 7663204
Please check my last comment answer is close to what I need. But no one answered my last comment so I haven't accepted anyone's answer till now.
If you can answer my last comment then I'll will accept that answer
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7663680
>>But how can I achieve it when entering text through code at runtime?

The way to do this is to use code like that shown in from n_narayanan's example!  
1) Insert the text
2) Select it (programatically via SelStart and SelLength)
3) Then set the attributes (e.g. SelBold)

-- Dan
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7663986
What i said in first place?
:)
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7664873
Richie_Simonetti, Right, you are!  However, I think that the "gentle hint" or the "mysterious ambiguity" is not going to go too far with this User.  indianmunda is needing some very specific answers.
-- Dan
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7665041
That's OK. Just to state my point.
cheers
0
 

Expert Comment

by:SpideyMod
ID: 7755415
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question