Solved

Well I need a text box/pic box to make the text diff colored...

Posted on 1998-12-20
5
148 Views
Last Modified: 2010-05-03
Well see I need my rich text box/ pic box
(prefered it be a text box) to make the text diffrent colors for example:

Print "Hello" (in red)
Print "How are you today" (in blue)
End
'''
How would I go about doing this, I would really like code pls. but if have to an active X. Thanx so much!
1 more thing. I have tried ForeColor but that changed the whole text box. I need this to just make each line a diff color. Thanks so much!
0
Comment
Question by:Shroom
  • 4
5 Comments
 

Author Comment

by:Shroom
ID: 1451669
Edited text of question
0
 
LVL 3

Accepted Solution

by:
Sendoh earned 10 total points
ID: 1451670
Hi !

The code as follow :

Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long


Private Sub Command1_Click()
    Dim rc As RECT

    Picture1.ForeColor = &HFF00FF
    rc.Left = 0
    rc.Top = 0
    rc.Right = Picture1.Width
    rc.Bottom = Picture1.Height
    DrawText Picture1.hdc, "Testing", 7, rc, 0
   
    Picture1.ForeColor = &HFF0000
    rc.Left = 0
    rc.Top = 20
    rc.Right = Picture1.Width
    rc.Bottom = Picture1.Height
    DrawText Picture1.hdc, "Testing", 7, rc, 0
End Sub

Hope it'll help you !!
0
 

Author Comment

by:Shroom
ID: 1451671
I need it to be a text box, and also if i were to use a pic box
what would the code be to just make it the next line this like skipes to lines and I need it to be a suc for example:
Sub AddText(txt, color, obj as control)

can this be done or somthing similar, thanx!-
0
 

Author Comment

by:Shroom
ID: 1451672
Plus you have to adjust evry thing, to how long the text is, I need this to work no matter how long, I am making a chat program!! Thanx, sorry bout the inconvinence!
0
 

Author Comment

by:Shroom
ID: 1451673
Stamp This Code In A Module This Is The Code I figured It Out On My Own But I give U The Points Any Way!!


Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long



    Sub ColorText(txt, line, color, pbox As PictureBox)
        Dim rc As RECT
       Dim TLeng
       TLeng = Len(txt)
   
    pbox.ForeColor = color
    rc.Left = 0
    rc.Top = line * 10
    rc.Right = pbox.Width
    rc.Bottom = pbox.Height
    DrawText pbox.hdc, txt, TLeng, rc, 0
     
    End Sub

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now