Thread: colored text

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    113
    Rep Power
    11

    colored text


    hi all, how may I change some part of text color and font on RichEdit? Like that, for ex.

    If something Then
    RichEdit2.Lines.Add(IntToStr(i) + '. word: ' + str[i] + ' --> ' + tmp);

    May I change the color and the font name of the string "str[i]"? It wont affect to all text in richedit?
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4248
    If you change the SelAttributes property, all new text that is inserted will follow these properties. If you want to change the properties of existing text, you'll need to select the text that you want to change the color for using the SelStart and SelLength properties. Then, you can change the properties of this selected text (such as color, font, size etc.) by manipulating the SelAttributes properties.
    Code:
    var
    	nStart, nLen : integer;
    begin
    	nStart := 3;
    	nLen := 10;
    	RichEdit1.SelStart := nStart;
    	RichEdit1.SelLength := nLen;
    	RichEdit1.SelAttributes.Color := clRed;
    	RichEdit1.SelAttributes.Style := [fsBold, fsItalic];
    	RichEdit1.SelAttributes.Height := RichEdit1.SelAttributes.Height + 2;
    end;
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    113
    Rep Power
    11
    thank u so much in advice...
    what about the font name? selattributes dont have that property, only charset. how may I change the selected font in richedit then?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    113
    Rep Power
    11
    thank u so much in advice...
    what about the font name? selattributes dont have that property, only charset. how may I change the selected font in richedit then?
  8. #5
  9. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4248
    SelAttributes.Name is the font name.
    Code:
    RichEdit1.SelAttributes.Name := 'Times New Roman';
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    113
    Rep Power
    11
    lots of thanks, that really helped me a lot

IMN logo majestic logo threadwatch logo seochat tools logo