|
-
Jan 2nd, 2002, 01:14 PM
#1
Thread Starter
Junior Member
Change color of individual character in text box on error?
I am using the following code to change the color of text in Text2.Text when the user makes an error entering text displayed in Text1.Text. I would like to change the color of the error character only and this code changes color of all characters in Text2.Text. Any suggestions? Thanks!
Private Sub Text2_KeyPress(KeyAscii As Integer)
Text2.SelStart = Len(Text2.Text)
Text2.ForeColor = vbBlack
'Next lines check for end of Text1 to avoid run time errors
If Len(Text1) > Len(Text2) Then
Text1.SelStart = Text2.SelStart
Text1.SelLength = 1
If Asc(Text1.SelText) <> KeyAscii Then
Text2.ForeColor = vbRed
End If
If Text2.ForeColor = vbRed Then
sndPlaySound "C:\Windows\MEDIA\DING.WAV", SND_ASYNC Or SND_NODEFAULT
End If
If KeyAscii = 8 Then 'Stops DING WAV on Backspace Key
sndPlaySound " ", SND_ASYNC Or SND_NODEFAULT
End If
'If Text1.SelStart = Len(Text2.Text) Then
If KeyAscii = 8 Then
Text2.ForeColor = vbBlack
End If
On Error Resume Next
End If
End Sub
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
|