Solved

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

Posted on 1998-12-20
5
146 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
Comment Utility
Edited text of question
0
 
LVL 3

Accepted Solution

by:
Sendoh earned 10 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 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

10 Experts available now in Live!

Get 1:1 Help Now