Posted by
Jakub Pawlak in
Classes & Controls
Sep 23rd, 2009 |
no responses
TextArea control is a editable text area that you are using in text editors (notepad, word, openoffice, pages etc.) or IM. It can contain multiple lines of text and can display mixed fonts, font styles and sizes. Learn how can you use it!
Adding text to a TextArea
Add to the Window PushButton Control and double click on it. Then enter there the code below. It’s simply like in TextField.
1
| TextArea.Text = "REALbasic City sample text" |
Reading text from a TextArea
Reading the content from TextArea is extreme easy like this s = TextArea.Text. Here you got a example that shows Message Box:
1
2
3
4
5
6
7
| Dim s As String
Dim d as New MessageDialog //declare the MessageDialog object
Dim b as MessageDialogButton //handling the result
s = TextArea.Text
d.Message = s
b = d.ShowModal |
Changing selected text in TextArea
Every text editor has a option to change the style of the text. Here you can look how you can simple change the selected text in TextArea control to new color and new font with bold style. Add the code to PushButton Sub Action()
1
2
3
4
5
6
7
| Dim Black As Color
Black = RGB(0,0,0)
TextArea.SelTextFont = "Arial"
TextArea.SelBold = true
TextArea.SelTextColor = Black |
Changing string with TextArea
We can also change the text in string ex. by finding the word or by putting the cursor on indicated line. We will change the word “my” form text string by putting the cursor on 8 position and changing the next 2 letters to bold and red color.
1
2
3
4
5
6
7
8
| Dim text As String
text = "This is my string"
TextArea.StyledText.Text = text
TextArea.StyledText.Bold( 8, 2 ) = true
TextArea.StyledText.TextColor( 8, 2 ) = &cFF0020 |
Using Mask
Simply select TextArea in GUI builder Tab and then in Property and Value find Behavior -> Mask and place there ex. ###-##-####. You can also add a code in TextArea Sub Open(). Go to Window1 code editor Controls -> TextArea -> Open.
1
2
| TextArea.Mask = "###-##-####" //US Social Security number
TextArea.Mask = "(###) ###-####" //US Phone number, with area code |
Mask Character in TextArea
# – The single digit placeholder. Entry optional. If this position is left blank in the mask, it will be rendered as a space. Plus and minus signs are allowed. The user can type only a digit character in this position.
. – Decimal placeholder. The decimal placeholder that is actually used is specified in the user’s International settings. The character is treated as a literal (formatting) character for masking purposes.
, – Thousands separator. The thousands separator that is actually used is specified in the user’s International settings. The character is treated as a literal (formatting) character for masking purposes.
: – Time separator. The time separator that is actually used is specified in the user’s International settings. The character is treated as a literal (formatting) character for masking purposes.
/ – Date separator. The date separator that is actually used is specified in the user’s International settings. The character is treated as a literal (formatting) character for masking purposes.
\ – Mask escape character. Treat the next character in the mask as a literal. The escape character enables you to use the ‘#’, ‘&’, ‘A’, ‘?’ (and so on) characters in the mask. The escapted character is treated as a literal (formatting) character.
& Character or space placeholder. Valid values are the ASCII characters 32-126 and the non-ASCII characters 128-255.
C – Character or space placeholder, where entry is optional. It operates like the ‘&’ placeholder.
> – Convert all the characters that follow to uppercase. Uppercasing works beyond the ASCII range where appropriate, e.g., ü becomes Ü.
< – Convert all the characters that follow to lowercase. Lowercasing works beyond the ASCII range where appropriate, e.g., Ü becomes ü.
A – Alphanumeric character placeholder, where entry is mandatory.
For example, the spec “AAA” specifies three alphanumeric characters.
a -Alphanumeric character placeholder, where entry is optional.
0 – Any single digit between 0 and 9. Entry is required.
9 – Digit or space where entry is optional.
? – Alphabetic placeholder. Entry is optional.
L – Alphabetic placeholder. Entry is required. Any literal. All other symbols are displayed as literals for formatting purposes.
~ – Reserved for future use. If you use “~” it will trigger an exception error. Use \~ instead.
Using TextArea Property and Value
When you select TextArea in GUI builder you can change some Property and Value for this control. We have got there position properties (width, height), appearance (text color, border), font (text size, text font), initial state (default text), behaviors (mask, read only) or database binding. Please play with them for a wile to understand what is happening when you change the values.