Solved

Giving text a color

Posted on 2000-05-18
7
162 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…

758 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

22 Experts available now in Live!

Get 1:1 Help Now