Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Giving text a color

Posted on 2000-05-18
7
Medium Priority
?
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 30 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
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…
Suggested Courses

715 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