Solved

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

Posted on 1998-12-20
5
147 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now