Results 1 to 5 of 5

Thread: change text colors (Like Zelda on N64)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 1999
    Posts
    184
    Ever played zelda??

    When someone talks to you the more importain
    words are in red, places in green. and such.
    I want to do this to the game im making but
    I believe that impossable with the label COntroll.
    IS there one I could do that with, and or
    could I do that with the label controll?

    Evan Duffield --------
    --- [email protected]
    - -
    VB6 - Learning Edition
    - -


  2. #2
    Guest
    You could use a RichTextBox and set the BackColour to whatever you want and have the Locked property set to True so it will act as a label.

    Then you can put this code in the General Section

    Code:
    Option Explicit
    
    
    
    Private Sub HighlightText(sKeyword As String, iColour As Long)
    
    Dim nStart As Integer, sPrevChar As String, sNextChar As String
    
                                               
    nStart = InStr(1, LCase(RichTextBox1.Text), sKeyword)
                                                
                                                
    Do While nStart <> 0
    
    If nStart > 1 Then
        sPrevChar = Mid$(RichTextBox1.Text, nStart - 1, 1)
    Else
        sPrevChar = " "
    End If
                                                    
    
    If Len(RichTextBox1.Text) >= nStart + Len(sKeyword) Then
        sNextChar = Mid$(RichTextBox1.Text, nStart + Len(sKeyword), 1)
    Else
        sNextChar = " "
    End If
                                                       
    
    If (sPrevChar = Chr(32) Or sPrevChar = Chr(13) Or _
    sPrevChar = Chr(10) Or sPrevChar = Chr(9)) And _
    (sNextChar = Chr(32) Or sNextChar = Chr(13) Or _
    sNextChar = Chr(10) Or sNextChar = Chr(9)) Then
    
    With RichTextBox1
    
    .SelStart = nStart - 1
    .SelLength = Len(sKeyword)
    .SelColor = iColour
    .SelText = UCase(sKeyword)
    .SelStart = Len(RichTextBox1.Text)
    .SelColor = vbBlack
    
    End With
    
    End If
                                                  
    nStart = InStr(nStart + Len(sKeyword), LCase(RichTextBox1.Text), sKeyword)
    
    Loop
    
    End Sub
    Now put this code in a CommandButton.

    Code:
    Private Sub Command1_Click()
    
    With RichTextBox1
    .SelStart = 0
    .SelLength = Len(.Text)
    .SelColor = vbBlack
    .SelStart = Len(.Text)
    End With
                                
    ' Add more custom words here
    HighlightText "bowser", vbBlue
    HighlightText "danger", vbRed
    HighlightText "palace", vbMagenta
    HighlightText "mario", vbGreen
     
    End Sub
    when you type in the words bowser, danger, palace and mario, they will all turn into different colours when you click the Commandbutton.


  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    No haven't played zelda, but you can change the forecolor of a label. Also if you wan't you can draw diectly on the form, change forms forecolor and use print
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Guest
    But you might have a hard time trying to get the text whewre you want it on the form.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    No Meg, the form have a currentx and currenty property which is the next position to write.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width