How do I get bold and color text in a text box?

I want a text box and an area text box to have BOLD and UNDERLINED text and even color text in them but I can’t seem to make it work and even if I paste this type of text into one of these boxes I lose it when I save it.

Is there a different type of text box that I can use to do this or do I have to go in a whole new direction?

Thanks for any help you can give me.
Dave

What do you call “text box” ? A label, a TextField, a TextArea ?

What you are looking for is the StyledText property that‘s available in TextAreas but not in TextFields: http://developer.xojo.com/userguide/styled-text

TextField and Label do have bold and TextColor. No need to go into StyledText.

… And TextFields / TextAreas are sibclass of TextEdit !

So, use TextAreas…

Oh, sure you‘re right, Michel. I understood the question in the way that bold and color should be assignable to specified characters.

If it is about saving colors and text attributes for a complete text, you have to figure out a way to preserve this information and reconstruct it because obviously the Text property saves only the pure text. A TextArea might make this easier because you could use the RTF property of StyledText.

Thanks for all the help guys and your are right Ulrich I want to be able to save the Bold characters or words.

for example: my “text area box” has the term “SIN NO MORE is used 3 times in the bible” . and I want the words SIN NO MORE to be in bold text and be able to save it.

I’m real happy to because it sounds like I can do it. I just need a little more help in doing it. as I haven’t worked with styled text or RTF test before.

Keep the help coming as I need all I can get. An example would be great.

Thanks
Dave

PS: I tried to bold the term SIN NO MORE in the reply and all I got was SIN NO MORE but no bold.

I’ll be darn the bold didn’t show up when I wrote the reply but did when I posted the reply it did. That is how I want it to work in my text area box.

Dave

Have a look at the built-in examples:Text/StyledText. While it does not really show how to save and load formatted text, you‘ll get an idea how to format styledText.

For saving and loading, look at the LR link I sent above. The language reference gives an example on how to save it via its RTFData property. Loading would be the opposite: Read an RTF file and assign it to the StyledText.RTFData property of a TextArea.

This forum software is not really WYSIWYG. There‘s a Preview checkbox at the upper right corner that does exactly that: give you an impression on how your text will look after posting it.

Ulrich With your help I’m making progress. I can now highlight the text I want to bold and I can bold it. Just like I want. I really feel good about what it. your giving me hope.

But now my problem is that I can’t save it. and I did not see your LR link that you sent above. All I see is the styled text that you posted above but I did not see a saving or reading of the text area box anywhere in it. I probably just missed it or I’m not understanding what I’m seeing.

I’m sorry to say I need a little more help on saving and read text with bold in it.
Dave

Happy to hear that, David!
I was not aware you cannot copy deep links from the LR. I wanted to point to the RTFData property of TextArea which has a save example:

Dim f As FolderItem = GetSaveFolderItem(TextTypes.TextRtf, "TestSaveRTF") If f <> Nil Then Dim s As TextOutputStream=TextOutputStream.Create(f) s.Write(TextArea1.StyledText.RTFData) s.Close End If

RTFData is simply a string, so you are not bound to saving it in a file – you could put the data in a database or whatever you want to use for storing the text. The LR examples on TextInputStream, if you want to follow the example above, should give you a clue about restoring the StyledText.

Don‘t be confused if the code above won‘t run. It accesses a FileTypeset “Texttypes” that will not appear in your project. You can replace the first line by

Dim f As FolderItem = GetSaveFolderItem("application/rtf", "TestSaveRTF")

Ulrich

Since this is a string why can’t I ( or will I ever be able) to save it to a field in my sql light data base and read it back?

I save it as str__Field_06 (which is Field 6 in my DB) = txaRemarksComments.StyledText.RTFData

when I read str__Field_06 back I got
“{\rtf1\ansi\ansicpg1252{\fonttbl{\f0\fnil courier new;}}{\colortbl\red0\green0\blue0;}\uc0 \ql\f0\fs32 How now Brown Cow. this is a test then nnniewv}”

“How now Brown Cow. this is a test then nnniewv” was the original string.

Would this be correct ? And all I have to do is decode this RTF string back encoded RTF string when I read it back in?

Dave

Yes, you can save the string in a database.
The string you copied is a perfect representation of an RTF string.
So yes, you would just have to assign it to the TextArea again:

txaRemarksComments.StyledText.RTFData = str__Field_06

Ulrich

Sorry but it didn’t work it gave me the original line but not bolded.

I have to go and will kook it tomorrow morning when I may see what is going on better.
unless you have some more ideas of what is going on.

Dave

David:

if you use TextArea check the Styled CheckBox (else, no style)…

Super have to be TextArea.

Look the last example @:
http://documentation.xojo.com/index.php/StyledText

And guess how to read it back.

You can also get an eye on:
StyledText.xojo_binary_project

in the Example Projects:Text: folder.

I have made no progress I use the command:

txaRemarksComments.StyledText.RTFData = “{\rtf1\ansi\ansicpg1252{\fonttbl{\f0\fnil courier new;}}{\colortbl\red0\green0\blue0;}\uc0 \ql\f0\fs32 This is a test of bold 40}”

and all I get is “This is a test of bold 40” but nothing is in bold.

The only thing I can think is that the saved string does not contain information for what characters need to be BOLD.

I don’t see any information about bold in the string. Maybe the colors aren’t right for bold?

I am at a loss that unless someone can figure out what I’m doing wrong I’m dead in the water.

Thanks for trying to help

Dave

Use TextEdit (Apple) Or WordPad (Windows) and load the rtf as data, then render them to be sure your rtf is correct.

Is not correct, you are right. This is not a Xojo bug.

[code]{\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf470
{\fonttbl\f0\fmodern\fcharset0 CourierNewPSMT;\f1\fmodern\fcharset0 CourierNewPS-BoldMT;}
{\colortbl;\red255\green255\blue255;}
\paperw11900\paperh16840\vieww12000\viewh15840\viewkind0
\deftab720
\pard\pardeftab720\partightenfactor0

\f0\fs32 \cf0 This is a test of
\f1\b bold 40}[/code]
The above is correct (bold 40 will appears in bold).

You can also read the rtf reference manual to know how from nothing you have to write rf text, maybe.

The alternate question can be:

How do you set and what text in Bold ?

I sent the rtf text too fast…

Copy the rtf text and paste it in TextEdit. Then save the text in a rtf file (set rtf as the extension and uncheck the txt efault). Then load that file in your runnin project (or application).

You now certainly have bold 40.