Some time ago, I've realised my idea about definable buttons:
After selecting this function, you can define caption of button, action realised by button and its action.
You can also decide if the button is active - visible.
I've used arrow keys to navigate in "excel" style:
Code: Select all
ON KEY DOWN OF OknoGlowne ACTION ChangeActiveButton("DOWN")
ON KEY UP OF OknoGlowne ACTION ChangeActiveButton("UP")
ON KEY RIGHT OF OknoGlowne ACTION ChangeActiveButton("RIGHT")
ON KEY LEFT OF OknoGlowne ACTION ChangeActiveButton("LEFT")
.
.
.
function ChangeActiveButton
param cDirection
local cNameofButton, lLoop := .f.
cNameofButton := "BUTTON_"+alltrim(str(nActiveRow))+"_"+alltrim(str(nActiveCol))
SetProperty("MainForm", cNameofButton,"FontBold",.f.)
do case
case cDirection == "DOWN"
do while .t.
if ++nActiveRow > nMaxRow
nActiveRow := 1
if lLoop
exit
endif
lLoop := .t.
endif
if aButtonsDefinition[ nActiveRow, nActiveCol, 3]
exit
endif
enddo
case cDirection == "UP"
do while .t.
if --nActiveRow = 0
nActiveRow := nMaxRow
if lLoop
exit
endif
lLoop := .t.
endif
if aButtonsDefinition[ nActiveRow, nActiveCol, 3]
exit
endif
enddo
case cDirection == "RIGHT"
do while .t.
if ++nActiveCol > nMaxCol
nActiveCol := 1
if lLoop
exit
endif
lLoop := .t.
endif
if aButtonsDefinition[ nActiveRow, nActiveCol, 3]
exit
endif
enddo
case cDirection == "LEFT"
do while .t.
if --nActiveCol = 0
nActiveCol := nMaxCol
if lLoop
exit
endif
lLoop := .t.
endif
if aButtonsDefinition[ nActiveRow, nActiveCol, 3]
exit
endif
enddo
endcase
cNameofButton := "BUTTON_"+alltrim(str(nActiveRow))+"_"+alltrim(str(nActiveCol))
DoMethod("MainForm",cNameofButton,"SETFOCUS")
SetProperty("MainForm", cNameofButton,"FontBold",.t.)
return
These buttons are created in this way:
Code: Select all
for r := 1 to nMaxRow
for c := 1 to nMaxCol
//msgbox(hb_valtoexp(aButtonsDefinition[r,c][4]))
xIkona := alltrim(aButtonsDefinition[r,c][4])
if empty(xIkona)
xIkona := "MALYPUSTY"
endif
cNameOfButton := "Button_"+alltrim(str(r))+"_"+alltrim(str(c))
cAkcja := "AktionTestButton("+alltrim(str(r))+","+alltrim(str(c))+")"
DEFINE BUTTON &cNameOfButton
ROW 40+(r-1)*70
COL 20+(c-1)*150
CAPTION aButtonsDefinition[r,c,2]
PICTURE xIkona
PICTALIGNMENT Left
WIDTH 140
HEIGHT 60
FONTNAME "ARIAL"
FONTSIZE 11
VISIBLE aButtonsDefinition[r,c,3]
MULTILINE .T.
ONCLICK &cAkcja
END BUTTON
next c
next r