Labels and OnMouseHover
Posted: Mon Jun 20, 2016 8:19 am
Hi guys!
I was interested if there is a method to create use interface similar to webpage, where label color is changed on mouse hover.
I want to share small sample which realize this idea.
Thanks to Andyglez for his tip
I was proposed additional feature for LABEL control to Claudio for vertical center align.
In connection with this, It's possible to create interface similar to Windows 10 or www page.
Nice testing!
I was interested if there is a method to create use interface similar to webpage, where label color is changed on mouse hover.
I want to share small sample which realize this idea.
Thanks to Andyglez for his tip
Code: Select all
// OnMouseHover demo
// 2016.06.20 Marek Olszewski
#include "hmg.ch"
Function Main
private aLabelColors := { => }
aLabelColors [ "KAFEL1" ] := {100,100,100}
aLabelColors [ "KAFEL2" ] := {100,200,0}
aLabelColors [ "KAFEL3" ] := {0,200,200}
// turn off case sensitive hash keys matching
hb_HCaseMatch(aLabelColors, .F.)
DEFINE WINDOW Form_Main ;
AT 0,0 ;
WIDTH 640 HEIGHT 600 ;
TITLE 'Main Window' ;
MAIN
@ 60,10 LABEL KAFEL1 ;
WIDTH 200 HEIGHT 200 ;
VALUE "OPTION 1";
BACKCOLOR aLabelColors [ "KAFEL1" ];
CENTERALIGN
@ 60,220 LABEL KAFEL2 ;
WIDTH 200 HEIGHT 200 ;
VALUE "OPTION 2";
BACKCOLOR aLabelColors [ "KAFEL2" ];
CENTERALIGN
@ 270,220 LABEL KAFEL3 ;
WIDTH 200 HEIGHT 200 ;
VALUE "OPTION 3";
BACKCOLOR aLabelColors [ "KAFEL3" ];
CENTERALIGN
@ 270,10 LABEL KAFEL4 ;
WIDTH 200 HEIGHT 200 ;
VALUE "STATIC OPTION NOT COLORIZED";
BACKCOLOR {255,255,255};
CENTERALIGN
END WINDOW
CENTER WINDOW Form_Main
CREATE EVENT PROCNAME OnMouseHover( EventWPARAM(), "FORM_MAIN" ) HWND Form_Main.Handle
ACTIVATE WINDOW Form_Main
Return
*---------------------
function OnMouseHover
param hWnd, cFormName
LOCAL cControl := ""
LOCAL cForm := ""
static cPrevious := ""
GetControlNameByHandle( hWnd, @cControl, @cForm )
if empty(cControl)
if !empty(cPrevious)
// set oryginal color to previous control
SetProperty(cFormName, cPrevious, "BackColor",aLabelColors [ cPrevious ])
//to prevent flickering
cPrevious := ""
return
endif
endif
// to avoid errors - eliminate changes for absent controls in aLabelColors array
if HB_HPOS( aLabelColors, cControl) == 0
return
endif
if !empty(cPrevious)
// to avoid flickering
if !(cControl == cPrevious)
SetProperty(cFormName, cPrevious, "BackColor",aLabelColors [ cPrevious ])
endif
endif
SetProperty(cForm, cControl, "BackColor",{255,255,0})
cPrevious := cControl
return
In connection with this, It's possible to create interface similar to Windows 10 or www page.
Nice testing!