The REALbasic StyledText Class enables you to apply style attributes to the TextArea Control. We can use it to create MS Word like application or syntax highlight for TextArea Control. Learn some basic about StyledText Class available in REALbasic.
Because the TextArea already has selection style attributes, the StyledText class honors that information. This means that you can set the style information using the selection methods that are available within the TextArea class, and they will be reflected when getting StyleRun information (and vice versa). Not all of the style attributes for selections in the TextArea class are available in the StyleRun class, such as Outline, Condense, Shadow, and Extend. These were supported only on Mac OS “classic”.
The following example uses the methods of the StyledText class to mark up and align text and display it in a TextArea. In order for the styled text to display, you must turn on the Multiline and Styled properties of the TextArea.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | Dim Text As String // text to be displayed in TextArea Dim st,ln As Integer // start and length values of a paragraph //define four paragraphs in Text Text = "This is the text that we are going to save " _ +"into our file from the TextArea."+EndofLine _ +"Isn't that interesting?"+EndofLine _ +"Man, I sure do love using RB to take care of my projects."+EndofLine _ +"That's because the RS Engineering staff is just so awesome!" TextArea1.StyledText.Text = text //four paragraphs in Text TextArea1.StyledText.Bold(5, 2) = True TextArea1.StyledText.TextColor(5, 2) = &cFF0000 //bold and red TextArea1.StyledText.Size( 7, 10) = 16 TextArea1.StyledText.Underline(12, 4) = True //16 pt underline TextArea1.StyledText.Size(100, 4) = 18 TextArea1.StyledText.TextColor(100, 4) = &cFF00FF //18 pt and Magenta TextArea1.StyledText.Font(0, Len(text) ) = "Comic Sans MS" //center aliign second paragraph TextArea1.StyledText.ParagraphAlignment(1)=Paragraph.AlignCenter //set this paragraph in Helveticta, 18 pt bold, red //first get the start and length values for this paragraph... st=TextArea1.StyledText.Paragraph(1).StartPos ln=TextArea1.StyledText.Paragraph(1).Length+1 //next apply attributes... TextArea1.StyledText.Bold(st,ln)=True TextArea1.StyledText.Font(st,ln)="Helvetica" TextArea1.StyledText.Size(st,ln)=18 TextArea1.StyledText.TextColor(st,ln)=&cFF0000 |
The following code, appended to the end of the previous method, saves the styled text to disk in RTF format. It assumes that the File Type Set, “TextTypes” has one item, TextRTF, that defines the RTF file type
1 2 3 4 5 6 7 | Dim s As TextOutputStream Dim f As Folderitem f=GetSaveFolderItem(TextTypes.TextRtf,"TestSaveRTF") s=TextOutputStream.Create(f) s.Write TextArea1.StyledText.RTFData s.Close |
How do I create a link with REALbasic?
Link in TextArea Control or a simple text link ?
into TextArea Control and into listbox (if possible)
In TextArea Control this is hard to do but i think that in listbox this can be done. I will think about a solution
Thanks Jakub, you’re helping a lot in my projects!
Hi Jakub,
nice introductory tutorial. I’m playing with the StyledText directly in the code, something like:
Dim st As New StyledText
st.Text = “some text here”
st.Bold(…) = True
etc.
When I finish all the styling then I do a Preview.efPreview.StyledText = st, and my problems begin. All styles are well aplied except for paragraph alignment. All paragraphs get the alginment of the last one (if the last one is left, all are left, altough I’ve set it up for being right or center). Do you have any idea of whats happening?
Thanks!
PS: I’ve tryied this on RB2007 and RB2008 (i don’t have 2009 or 2010 to test)
Hello Marc,
unfortunately I have no idea what can be wrong, but I will try to think about it and get a solution when I will have a little more time.
hi Jakub,
is possible color scrollbars like itunes scrollbar?
thanks
Daniele
Hi matt86,
there is a way to do this but you must create own control using Canvas. The default Scrollbar Control available in REALbasic doesn’t offer this kind of option.
You could make a tutorial for color scrollbars?
I try to make this kind of tutorial. I will add this to my REALbasic City task
In few days there will be a tutorial for PM about creating autocomplete TextEdit Control.
Thank you for everything Jakub, you’re helping a lot in my projects!
Thank you Daniele and thank you for supporting REALbasic City