1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Color text in VB

Discussion in 'Software Development' started by JoeLeanza, Oct 10, 2003.

Thread Status:
Not open for further replies.
Advertisement
  1. JoeLeanza

    JoeLeanza Thread Starter

    Joined:
    Jun 10, 2003
    Messages:
    37
    I am trying to have multiple font colors in a VB Text box.

    I have tried to change the color of the first three letters using this statement
    Mid(txtBox.ForeColor, 1, 3) = "red"

    When I run it I get an error box that says
    "Variable required
    Can't assign this expression"

    The ForeColor statement is highlighted.

    I appreciate Any help or thoughts.
     
  2. moebius

    moebius

    Joined:
    Oct 7, 2003
    Messages:
    1,741
    u cant change the color of a single character in a text-box in vb without changing the others. if uve seen that done and want to mimic it, its usually done with a Rich Text Box. to use the rich text box control, u must add the component to ur project. sometimes its called microsoft rich edit text box or just riched32.dll
    good luck
    -PS : i think the same effect can be applied to a standard text box using windows api. that would save rescources as ur program woudlnt have to load an extra dll. but im not that thorough with the windows API
     
  3. JoeLeanza

    JoeLeanza Thread Starter

    Joined:
    Jun 10, 2003
    Messages:
    37
    Thanks a bunch, next problem is how.
    I coded
    Mid(txtBox.ForeColor, 1, 3) = "red"
    and got an error message
    "Method or Data Member not found"
    The ForeColor statement is highlighted.

    Help again
     
  4. JoeLeanza

    JoeLeanza Thread Starter

    Joined:
    Jun 10, 2003
    Messages:
    37
    Whoops the code should say
    Mid(rtbBox.ForeColor, 1, 3) = "red"
     
  5. moebius

    moebius

    Joined:
    Oct 7, 2003
    Messages:
    1,741
    what i forgot to tell you was that by:

    Mid(rtbBox.ForeColor, 1, 3) = "red"

    you are not changing the forecolor property of part of the richtext box. you are changing the forecolor propert of the string value. variables dont have properties/methods in vb.

    rich text formatting is much like HTML. although i dont know a lot about rich text, private message me ur email and ill send u a zip file that contains instructions/specifications about the basic usage of the rich text format.

    OR

    you could just open wordpad, write down some text, give different parts of the text different fonts, colors, sizes etc. and then save it as a txt file. when u open this file in notepad, you can see the rich text and learn from it. it is quite easy.

    edit
    Ive got some code for u analyse it urself:

    Code:
    {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}{\f1\fswiss\fprq2\fcharset0 Verdana;}}
    {\colortbl ;\red0\green255\blue255;\red0\green0\blue128;\red255\green0\blue0;\red0\green128\blue0;\red128\green0\blue128;\red0\green0\blue0;}
    \viewkind4\uc1\pard\f0\fs20 Standard Text\par
    \par
    \fs52 26 point Standard Text\par
    \par
    \fs18 Smaller Text\par
    \par
    \i Italicised Text\par
    \par
    \b\i0 Bold Text\par
    \par
    \ul\b0 Underlined Text\par
    \par
    \ulnone\b\i Bold Italicised Text\par
    \par
    \ul\i0 Bold Underlined Text\par
    \par
    \cf1\ulnone\b0 Aqua Colored Text\par
    \cf2\par
    Navy Colored Text\par
    \par
    \cf3\b Bold, Red Text\par
    \par
    \f1 Bold, Red Verdana Text\par
    \par
    \b0\i Red Italicised Verdana Text\par
    \par
    Multi-\cf2 Colored \cf4 Italicised \cf5 Text\par
    \par
    \cf6\fs20 - M\'f6bi\'f9s The Infinidude\cf0\i0\f0\par
    }
     
    
    to set the rtf code of a rich text edit box. use the richtect property.
    (
    riched1.richtext = "\cf3 \b Bold, Red Text\par\parThis is on a nelwline"
    )

    leave out the parantheses though
     
  6. moebius

    moebius

    Joined:
    Oct 7, 2003
    Messages:
    1,741
    NOTE: in the previous example, i forgot to mention that u need to give the rich text a header,

    im sure this code is leaky, so u better google rich+text+format+specification. Sorry
     
  7. JoeLeanza

    JoeLeanza Thread Starter

    Joined:
    Jun 10, 2003
    Messages:
    37
    Thanks for your effort, We got it to work
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/171061

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice