Thursday, April 12, 2007

SnTT: Toolbar Icon to Change Font Colors

This is a quick and dirty tip inspired by a request from a co-worker the other day. He wanted to know if there was a way to quickly change font colors in Notes, similar to the buttons available in Microsoft applications. I said I wasn't aware of one and couldn't locate one after some searching. So, since he's a good guy, and I like to keep people happy with Notes, I decided to write something quickly.

This is the code:
colorchoices:="Black":"Gray":"Red":"DarkRed":"Green":"DarkGreen":"Blue":"DarkBlue":
"Magenta":"DarkMagenta":"Yellow":"Brown":"Cyan":"DarkCyan":"White";
colorcodes:=[Black]:[Gray]:[Red]:[DarkRed]:[Green]:[DarkGreen]:[Blue]:[DarkBlue]:[Magenta]:[DarkMagenta]:[Yellow]:[Brown]:[Cyan]:[DarkCyan]:[White];
newcolor:=@Prompt([OkCancelList];"Choose a Color";"Choose the color to apply to the text: ";"Black";colorchoices);
@If(newcolor="[]";@Return("");
@Command([TextSetFontColor];@Subset(@Subset(colorcodes;@Member(newcolor;colorchoices));-1)))

I set the button caption to 'Change Font Color' and popup help to 'Change the font color' and chose the toolbar_paintblu.gif icon from the list of available icons.

Note that I said this was "quick and dirty". The code could probably be more efficient but it is functional. Note also that this button will work to set a font color at the insertion point or to change the color of selected text.

Enjoy!

Technorati:

1 comment:

Unknown said...

I have used this approach for making toolbar-buttons for setting different styles/colors on text both in the client and in the designer.

In the designer, for instance, there is an option to add hidden comment. Red color, normal font, html-comment "syntax".

<!-- [result from prompt for hidden text] -->

Although the comment is not hidden (you can't control hide-when with formula), they follow my standard structure for hidden text. I have to manually hide the text after it's inserted.