Solved

Giving text a color

Posted on 2000-05-18
7
163 Views
Last Modified: 2012-05-04
Hello,

Who knows how to.... I created a text field called text1 that is not one rule but a field !!
Now my question is: How can i when the user types a certain word give that word a color just like
visual basic does with sub etc.
eg i want when the user typs print print colors blue and so on. who knows...

Mark
0
Comment
Question by:markyvt
7 Comments
 
LVL 2

Expert Comment

by:BobbyOwens
ID: 2820862
You will probably need to use a rich text box. With a rich text box, you can colour different parts in different colours. as the user types, you will need to run some code to check if the word exists and then select and colour it.
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2820909
This site has a sample with RichTextBox text in colors:

http://www.vbexplorer.com/VB_String_Text.asp

Actual download at:

http://www.vbexplorer.com/files/colortag.zip

Core code is:

RichTextBox1.SelStart = 3  ' Some Start Value
RichTextBox1.SelLength = 5  ' Some Length Value
RichTextBox1.SelColor = vbRed  ' Some Color
0
 
LVL 9

Accepted Solution

by:
Ruchi earned 10 total points
ID: 2821818
Use richtextbox’s properties: SelLength and SelStart.

The SelStart property of richtextbox is 0-based. So for instance, (using | to represent the insertion point, and [       ] to represent a richtextbox)

[|H e l l o M w a m !       ]

SelStart = 0, and

[ H e l l o M| w a m !       ]

SelStart = 7


a very small program...

richtextbox1.Text = "Hello my friend!"
richtextbox1.SelStart = 0
richtextbox1.SelLength = 5
richtextbox1.SelColor = vbBlue
richtextbox1.SelStart = 6
richtextbox1.SelLength = 2
richtextbox1.SelColor = vbGreen
richtextbox1.SelStart = 9
richtextbox1.SelLength = 7
richtextbox1.SelColor = vbRed
richtextbox1.SelStart = 11

Hope this helps.
0
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.

 
LVL 28

Expert Comment

by:AzraSound
ID: 2821822
you will have to watch the keydown event of the richtextbox.  say the word is "public" that you are looking for...you will need a temp string that is always reset after a space (or other punctuation depending on you) and then check for the next letters.  if the first after the space is a p then we're still good to go, and then next a u...etc.  once you get a mismatch you dont have to check anymore until you get another space.
0
 
LVL 2

Author Comment

by:markyvt
ID: 2824426
It's helping, but like with an html editor and so it opens a file and colors <html> <head> and so on how can i do that??
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2824449
see this sample:

"Color HTML tags in a RichTextBox quickly (7K)"

http://www.vb-helper.com/Howto/tagcolor.zip
0
 
LVL 2

Author Comment

by:markyvt
ID: 2903438
Comment accepted as answer
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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

911 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

19 Experts available now in Live!

Get 1:1 Help Now