|
-
Dec 23rd, 1999, 01:38 PM
#1
Thread Starter
New Member
can some one please tell me how to make the text color change if the text is a certain thing??? (like on html editors.....when you type <./h1> the color is green)
-
Dec 23rd, 1999, 05:06 PM
#2
Frenzied Member
You can use the BackColor and ForeColor statements.
To the change the ForeColor on a label, type the folowing code: (Place a label on a form)
Private Sub Form_Load()
Label1.ForeColor = &HFF&
End Sub
Use the same methods with the BackColor(use another color : O ))
-
Dec 24th, 1999, 05:46 AM
#3
Thread Starter
New Member
thank you for the reply but i already know how to do that but i need to know how to change the color if the TEXT is a certain string......for example:
Private Sub Text1_Change()
htmlstring = text1
if htmlstring = "<h1>" then
text1.forecolor = "&h0"
End if
End Sub
do ya get what i mean now????
-
Feb 12th, 2000, 09:20 AM
#4
Member
look for something called HTML TAG, it will change the < , > , and everything in between
-
Feb 12th, 2000, 12:54 PM
#5
Hyperactive Member
This same question has been asked many times not long before in this Forum. Do a search with html, color, tags, RichTextBox, etc. and you'll find something I'm sure...
-
Feb 12th, 2000, 01:40 PM
#6
Here's some Code I posted a while back on the same question, although you can't use a Standard Textbox, (It doesn't support multicolored text), so you'll have to use a RichTextBox:
Code:
Private sLookUp(9, 1) As String
Private Sub Form_Load()
'Create Lookup Table
sLookUp(0, 0) = "vb-world"
sLookUp(0, 1) = Trim(Str(vbBlue))
sLookUp(1, 0) = "is"
sLookUp(1, 1) = Trim(Str(vbRed))
sLookUp(2, 0) = "the"
sLookUp(2, 1) = Trim(Str(vbGreen))
sLookUp(3, 0) = "best"
sLookUp(3, 1) = Trim(Str(vbCyan))
'Add More Here
End Sub
Private Sub RichTextBox1_KeyUp(KeyCode As Integer, Shift As Integer)
'Find the Word Currently under the Text Caret
Dim iStart As Long
Dim iEnd As Long
Dim iMatch As Integer
Dim sKeyWord As String
Dim iPos As Long
With RichTextBox1
iPos = .SelStart
If iPos Then
If Mid(.Text, iPos, 1) <> " " Then
iStart = InStrRev(.Text, " ", .SelStart) + 1
iEnd = InStr(iStart, .Text, " ")
If iEnd = 0 Then iEnd = Len(.Text)
'Check for a Match
sKeyWord = Trim(Mid$(.Text, iStart, iEnd - iStart + 1))
Caption = sKeyWord & " : " & Len(sKeyWord)
iMatch = MatchKeyWord(sKeyWord)
.SelStart = iStart - 1
.SelLength = Len(sKeyWord)
If iMatch Then
.SelColor = Val(sLookUp(iMatch - 1, 1))
Else
.SelColor = vbBlack
End If
.SelStart = iPos
End If
End If
.SelColor = vbBlack
End With
End Sub
Private Function MatchKeyWord(ByVal sWord As String) As Integer
'Check Word for a Match in the Lookup Table
Dim iLookUp As Integer
For iLookUp = 0 To UBound(sLookUp)
If LCase(sWord) = LCase(sLookUp(iLookUp, 0)) Then Exit For
Next
If iLookUp <= UBound(sLookUp) Then MatchKeyWord = iLookUp + 1
End Function
Private Function InStrRev2(ByVal sString As String, ByVal sChars As String, Optional ByVal lPos As Long = 1) As Long
'Duplicate of the VB6 Function InstrRev
'If you Don't have VB6, Rename InStrRev in the
'KeyUp Event to InstrRev2 to use this Routine instead.
If Len(sString) = 0 Then Exit Function
If lPos = 1 Then lPos = Len(sString)
While Mid(sString, lPos, 1) <> sChars And lPos > 1
lPos = lPos - 1
Wend
If lPos = 1 And Left(sString, 1) <> sChars Then
InStrRev2 = 0
Else
InStrRev2 = lPos
End If
End Function
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
Certified AllExperts Expert
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|