Coloured Buttons on Forms in a MS Windows Environment 

Anyone who programs using the Oracle forms development system on a regular
basis can't help but be impressed with its environment, power and ease of
use. I am a great fan but there are a few little niggles I have with it which
just don't sit right with me and one of these is the issue of changing the colour
of buttons on a form. A simple thing I know, but I'll be darned if you can't
do it (as far as I'm aware this is not a problem with non-Microsoft windowing
environments). Yes, with all its fancy graphics and a zillion functions to do almost anything you want, you cannot change or set the colour of a simple button in Forms.

Right away I'll come clean and say that we're going to fix the coloured button problem by not using buttons at all. On your form they'll look like buttons, behave like buttons and do almost everything a button does but they won't be buttons, in fact they'll be images that look like buttons. Note that I'm not talking here about iconic buttons which are often put forward as a way of overcoming the coloured button problem. They are generally too small to be of any practical use.

You want coloured buttons on your forms? Follow these steps.

The first thing you'll need is an image of a button so either get one from the Net or create one yourself using something like MS Paint or Paintshop Pro. There is also plenty of good quality free and shareware applications you can download which will also do the job. If you don't have access to the NET then any cover CD from a decent computer magazine will also have the necessary software on it to create your own button. Whichever method you use, you need to ensure that you end up with a coloured rectangle with some appropriate text in the middle of it that looks more or less like a button. Also make sure it's saved in a file format that FORMS can handle (.e.g. TIFF, BMP and GIF amongst many others).

Next, open up a blank form and put an image item onto it. The default
properties for this should be fine as they are; you can always tweak them later
to suit your specific requirements. The only property we need to worry about
at this stage is the BORDER BEVEL property and that should be set to RAISED. On
the WHEN-NEW-FORM-INSTANCE trigger you can put your READ_IMAGE_ITEM code. Hey presto, when you run the form you should now have what passes for a coloured button on it. Now we need to make it act like a proper button.

Create two new WHEN-MOUSE-DOWN/UP triggers for your "button" at the FORM level not at the item level (more about why this is done later). Depending on the complexity of your form and its presentation to the end-user you may want to compare the mouse x-y coordinates when you press the mouse button down/up to those of the button's location on the form before performing any other actions. In other words you may only want the mouse action to operate the button when the mouse cursor is over the button. The only action your WHEN-MOUSE-DOWN trigger will need to do is to set the BORDER BEVEL property of your button to LOWERED using SET_ITEM_PROPERTY. Your WHEN-MOUSE-UP trigger should re-set the BORDER BEVEL property of your button to RAISED, followed by a SYNCHRONIZE before continuing with any other code that your button needs to perform. Putting the SYNCHRONIZE in means that your users will see the button pop back up straight away even if the subsequent code it performs is lengthy.

Now we come to why I asked you to put the WHEN-MOUSE-UP/DOWN triggers
at the FORM rather than at item level. The reason is this. When I first used coloured buttons everything looked OK but I found that when I clicked on the image and held the mouse down and then dragged it, little rectangular outlines would be drawn over the image. I didn't like this much and discovered that the answer was to disable the image item. However the side effect of this is that you
cannot use the WHEN-MOUSE-UP/DOWN triggers on an item that is disabled hence the need to move them elsewhere.

​A selection of topics on IT and its application to finance. 
​Send me your comments, questions ​or suggestions by clicking