Solved

Giving text a color

Posted on 2000-05-18
7
166 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 Compile Compatibility Issue 4 130
VB6 - Convert HH:MM into Decimal 8 75
I need help embedding an image as HTML in my vb.net application 3 84
2 Global Vars, 1 List Box 4 32
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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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