by Ursego » 30 Jan 2014, 09:18
Please read the description in the header comment:
- Code: Select all
/**********************************************************************************************************************
Dscr: Places passed controls (like buttons) in the center of their parent window HORIZONTALLY.
This function is useful when different sets of buttons are displayed under different conditions
and the buttons should be placed in the middle to look nice (no matter how many buttons).
For example, there are 4 buttons in the window - cb_ok, cb_yes, cb_no, cb_cancel:
CommandButton lcb_buttons[]
if <some condition> then
lcb_buttons[] = {cb_yes, cb_no, cb_cancel}
esle
lcb_buttons[] = {cb_ok, cb_cancel}
end if
gnvuo_util.uf_display_in_center(lcb_buttons[])
The function also makes the displayed controls visible, so make all the controls invisible by default.
***********************************************************************************************************************
Arg: ado_controls[] (array of DragObject)
***********************************************************************************************************************
Developer: Michael Zuskin - http://linkedin.com/in/zuskin | http://code.intfast.ca/
**********************************************************************************************************************/
int li_count // quantity of controlls to center
int i
int li_frag_len // "fragment" is the distance between the beginning of the 1st control and the end of the last one
int li_X
window lw_parent
constant int SPACE = 15 // between controls
li_count = UpperBound(ado_controls[])
if li_count = 0 then return
// Calculate fragment's length:
for i = 1 to li_count
li_frag_len += ado_controls[i].Width + SPACE
next
li_frag_len -= SPACE
// Calculate X coordinate (on the window) of 1st control:
lw_parent = ado_controls[1].GetParent()
li_X = (lw_parent.Width - li_frag_len) / 2
// Place all controls:
for i = 1 to li_count
ado_controls[i].Visible = true
ado_controls[i].X = li_X
li_X += ado_controls[i].Width + SPACE // "move" X to right, i.e. calc it for next control
next
return
For Canadians: you should name this function uf_display_in_centRE()!