Solved

Giving text a color

Posted on 2000-05-18
7
167 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 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 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…
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

628 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