Hi
I have TextArea into which I keep appending words or sentences.
Once in a while, I would like to have one of the words I append be “Bold”.
How do I do that without turning the whole TextArea to Bold?
Look at the StyledText reference.
ta.selstart=x
ta.sellength=y
ta.selbold=true
where x is start of word, and y is length of word
same works for italic, underline and color
I have looked at StyledText but since I want to bold just the one word as I append it to the TextArea (the word is on its own), I cannot seem to make heads or tails of Start and Length
If you are appending… then SELSTART is already set for you… and you know how long the word is you are about to append
ta.sellength=len(new_word)
ta.selbold=true
ta.seltext new_word
ta.selbod=false
ta.seltext="next word not bold"
Got it !!
Thanks a lot
again… the same works for Italic, Underline and Color
and you can set multple of those attributes at the same time if required… to have Bold/Underlined/Blue text for example
Just a warning if you are targeting Cocoa: not all fonts have Bold or Italic variation, and Cocoa wants a real font here, it doesn’t fake the bold as in past with Carbon. So chances are that for some fonts you set Bold and you get plain regular text.
There is no guarantee that the SelStart will be at the end of the text. What if the user highlighted something before you append?
I’d set ta.SelStart to ta.Text.Len first. If you want to preserve the user selection, restore it after you’re done, or use ta.StyledText to do the bolding.
dim savedSelStart as integer = ta.SelStart
dim savedSelLen as integer = ta.SelLength
ta.SelStart = ta.Text.Len
ta.SelBold = true
ta.SelText = new_word
ta.SelBold = false
ta.SelText = "next word not bold"
ta.SelStart = savedSelStart
ta.SelLength = savedSelLen