REALbasic – StyledText Class line

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.

StyledText Class 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”.

StyledText Class example in REALbasic

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

Save StyledText to file in REALbasic

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

Author: Kuba Pawlak

I'm interested in all. Currently working on the development of TUTSPOLIS and I hope that in near feature the project will be successful.

13 Responses to “REALbasic – StyledText Class”

  1. matt86 says:

    How do I create a link with REALbasic?

  2. Jakub Pawlak says:

    Link in TextArea Control or a simple text link ?

  3. matt86 says:

    into TextArea Control and into listbox (if possible)

  4. Jakub Pawlak says:

    In TextArea Control this is hard to do but i think that in listbox this can be done. I will think about a solution :)

  5. matt86 says:

    Thanks Jakub, you’re helping a lot in my projects!

  6. Marc says:

    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)

  7. Jakub Pawlak says:

    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.

  8. matt86 says:

    hi Jakub,
    is possible color scrollbars like itunes scrollbar?

    thanks

    Daniele

  9. Jakub Pawlak says:

    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.

  10. matt86 says:

    You could make a tutorial for color scrollbars?

  11. Jakub Pawlak says:

    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.

  12. matt86 says:

    Thank you for everything Jakub, you’re helping a lot in my projects!

  13. Jakub Pawlak says:

    Thank you Daniele and thank you for supporting REALbasic City :)

Leave a Reply

Copyrights (c) TUTSPOLIS | Powered by Wordpress MU | Inspired at Elegant Themes designed by qbap (HTML5 & CSS3)