by John Brinkman
In these times. many countries are interested in border control. Today I’m interested in controlling field borders. Did you know that fields have two borders? There is a border around the entire field (including the caption) and there’s a border around just the content part — excluding the caption. These are edited in two different places in the Designer UI. Field border is specified under the border tab:
The border around the content portion is specified in the "Appearance" selection of object/field:
Both of these borders can be manipulated in script. Have a look at this sample form to see what I mean.
You might notice that the scripts in the sample form do not use the field.borderColor or field.fillColor properties. These are shortcuts — convenience syntax that simplifies the underlying property structure. And while they’re convenient, they don’t give you full control. Most notably, they control only the outer border, do not give access to the widget border.
As you look at the script in the sample form, you will notice some interesting things:
1) script reflects syntax.
The (simplified) XML definition of a border looks like this:
<border presence="visible | hidden"> <edge presence="visible | hidden" thickness="measurement"> <color value="r,g,b"/> </edge> <!-- [0..4] --> <fill presence="visible | hidden"> <color value="r,g,b"/> </fill> </border>
A script that changes a border fill color (border.fill.color.value = "255,0,0";) is simply traversing the hierarchy of elements in the grammar.
2) Edge access is tricky
The syntax to get at the four edges uses the "getElement()" method, whose second parameter is the occurence number of the edge. Note that the sample always sets all 4 edges. This is because edge definitions are inherited. e.g. if only one edge is specified, then modifying the single edge property impacts all four edges. The problem is that you don’t always know how many edges have been specified, so it’s safest to set all four explicitly.
3) Show/hide with the presence property.
You’re likely accustomed to using the presence property of fields. That same attribute applies on the components of a border:
border.presence = "hidden"; // hides entire border — all edges and fill
border.fill.presence = "hidden"; // makes the border fill transparentborder.getElement("edge", 0).presence = "hidden"; // hides the first edge
4) There’s more.
There is more to the border definitions than I’ve shown you here. Using script you an control the four corners, fill patterns, edge thickness, border margins and more.
5) There are other borders
Subforms, rectangles, draw elements and exclusion groups all have border definitions.