There is the TextColor function you can apply to any portion of the text, or all of it.
Thanks. I've had a look and Yes, it's there. But the problem I have is scripting it to apply to the text field I'm typing in.
ANY thoughts are very welcome.
Building on David's reply:
Set Field [Table::Text ; Textcolor ( "This will be red text" ; RGB ( 255 ; 0 ; 0 ) ) ]
take a look at the object-level script triggers OnObjectModify and OnObjectKeystroke.
Thanks. Yes, that removes the content of a field and replaces it with "This will be red text" in red.
I however, simply want the text I am typing, from then on, to be "Red". Then, when I click on the Green Script, what I type from then on, will be Green. Until I press the Red Script etc.
The scripted equivalent of right clicking, selecting Text Colour from the menu, clicking on the colour of my choice, then carrying on typing.
Thanks!! Interesting idea for implementing the script. But I still don't have the script! Any thoughts on how the script it's self would work?
Note the time of my last reply. Your response had not appeared in my browser at the time I was composing it.
You might look at the insert calculated result step as it can insert formatted text at the point where you've currently placed the cursor, but you'll need to insert something to affect the color change--could be just a space, or you could select some text and then click your button in order to select a color for it--with the color staying as specified until you select a different color.
And there are functions that return the start and size of text currently selected in a text field.
Insert Calculated Result [TextColor ( Middle ( YourTable::YourTextField ; Get ( SelectionStart ) ; Get (SelectionSIze ) ) ; RGB ( 255 ; 0 ; 0 ) ) ]
You might also just expose the text formatting tool bar and use it to set text color--no scripting required.
You could probably use the OnObjectKeystroke script trigger - catch each keystroke and change the underlying field value based on the keystroke (applying the text color based on a global variable). However, the trick with OnObjectKeystroke is that it also traps non-alphabetic keys (such as tab, enter, arrow keys, etc.)
Yes, I've gone down that path a time or two. You can easily end up with a very complex script as you try to process all possible keystrokes correctly.
Try the attached file. It's a quick-and-dirty example of some of the triggered approaches mentioned by others here.
My OnObjectKeystroke triggered script acts on the contents of the $$text_color variable, set by one of the three buttons.
Set Variable [ $character; Value:Get(TriggerKeystroke) ]
Set Variable [ $code; Value:Code( $character ) ]
If [ $code = 8 ]
Exit Script [ Result: 1 ]
#Also handle other special character keystrokes
Set Variable [ $fieldname; Value:Get(LayoutTableName) & "::" & Get(ActiveFieldName) ] Set Variable [ $text; Value:Evaluate( $fieldname ) ]
Set Variable [ $pos_start; Value:Get(ActiveSelectionStart) ]
Set Variable [ $pos_size; Value:Get(ActiveSelectionSize) ]
Set Variable [ $character; Value:Let( char = $character;
$$text_color = "red";
TextColor( char; RGB( 250 ; 50 ; 50 ) ); $$text_color = "blue";
TextColor( char; RGB( 50 ; 50 ; 250 ) );
TextColorRemove( char ) )
#This script should do something different if text is selected
Set Variable [ $text; Value:Left( $text; $pos_start ) & $character & Right( $text; Length( $text ) - $pos_start ) ] Set Field By Name [ $fieldname; $text ]
Exit Script [ Result: 0 ]
OOK.fmp12.zip 69.1 K
I'm attaching a demo file so that you can actually see a possible script that you could use. It's not perfect, but it should get you started on your way (if you decide to go this route).
TextColour.fmp12.zip 66.5 K
Thanks!! I don't have a clue how you did this but I'll analyze what I have and I'm sure I'll get my head round it!!