Page 1 of 4

label at runtime

Posted: Tue Sep 05, 2017 4:55 pm
by jairpinho
Hello, I need to create 100 label at runtime, after the main window is already active to add in a graphic

Re: label at runtime

Posted: Tue Sep 05, 2017 8:45 pm
by edk
Hi.
Do you mean this behaviour?

Code: Select all

#include <hmg.ch>

Function Main

    DEFINE WINDOW main AT 108 , 360 WIDTH 550 HEIGHT 350 VIRTUAL WIDTH Nil VIRTUAL HEIGHT Nil TITLE "" ICON NIL MAIN CURSOR NIL ON INIT Nil ON RELEASE Nil ON INTERACTIVECLOSE Nil ON MOUSECLICK Nil ON MOUSEDRAG Nil ON MOUSEMOVE Nil ON SIZE Nil ON MAXIMIZE Nil ON MINIMIZE Nil ON PAINT Nil BACKCOLOR Nil NOTIFYICON NIL NOTIFYTOOLTIP NIL ON NOTIFYCLICK Nil ON GOTFOCUS Nil ON LOSTFOCUS Nil ON SCROLLUP Nil ON SCROLLDOWN Nil ON SCROLLLEFT Nil ON SCROLLRIGHT Nil ON HSCROLLBOX Nil ON VSCROLLBOX Nil

    DEFINE BUTTON Button_1
        ROW    280
        COL    30
        WIDTH  100
        HEIGHT 28
        ACTION AddPict()
        CAPTION "Picture"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

    DEFINE BUTTON Button_2
        ROW    280
        COL    410
        WIDTH  100
        HEIGHT 28
        ACTION AddLabels()
        CAPTION "Labels"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

END WINDOW
        Main.Center
        Main.Activate

Return


FUNCTION addPict()

IF IsControlDefined ( "Image_1" , "Main" )
	Main.Image_1.Release
	RETURN
ENDIF

DEFINE IMAGE Image_1
	PARENT Main
        ROW    30
        COL    60
        WIDTH  420
        HEIGHT 220
        PICTURE "img.jpg"
        HELPID Nil
        VISIBLE .T.
        STRETCH .T.
        ACTION Nil
    END IMAGE

RETURN
****************************************************************
FUNCTION AddLabels()
Local i, cLabelName

Local isControl:=IsControlDefined ( "L_1" , "Main")

FOR i=1 TO 100
	cLabelName:='L_'+ALLTRIM(STR(i))

	IF isControl

		DoMethod("Main", cLabelName, "Release")

	ELSE

	
	    DEFINE LABEL &cLabelName 
		PARENT Main
	        ROW    30+(20*int(i/10))
        	COL    60+(40*(i%10))
	        WIDTH  30
        	HEIGHT 20
        	VALUE ALLTRIM(STR(i))
	        FONTNAME "Arial"
        	FONTSIZE 9
	        VISIBLE .T.
	    END LABEL
	ENDIF
NEXT i
RETURN
By the way, I noticed the strange behavior of the IsControlDefined function:
IsControlDefined ( cLabelName , "Main") does not return "true" for the label controls already defined :shock:

Code: Select all

FUNCTION AddLabels()
Local i, cLabelName

FOR i=1 TO 100
	cLabelName:='L_'+ALLTRIM(STR(i))

	IF IsControlDefined ( cLabelName , "Main")

		DoMethod("Main", cLabelName, "Release")

	ELSE
	
	    DEFINE LABEL &cLabelName 
		PARENT Main
	        ROW    30+(20*int(i/10))
        	COL    60+(40*(i%10))
	        WIDTH  30
        	HEIGHT 20
        	VALUE ALLTRIM(STR(i))
	        FONTNAME "Arial"
        	FONTSIZE 9
	        VISIBLE .T.
	    END LABEL
	ENDIF
NEXT i
RETURN

Re: label at runtime

Posted: Wed Sep 06, 2017 1:29 am
by jairpinho
edk wrote:
Tue Sep 05, 2017 8:45 pm
Hi.
Do you mean this behaviour?

Code: Select all

#include <hmg.ch>

Function Main

    DEFINE WINDOW main AT 108 , 360 WIDTH 550 HEIGHT 350 VIRTUAL WIDTH Nil VIRTUAL HEIGHT Nil TITLE "" ICON NIL MAIN CURSOR NIL ON INIT Nil ON RELEASE Nil ON INTERACTIVECLOSE Nil ON MOUSECLICK Nil ON MOUSEDRAG Nil ON MOUSEMOVE Nil ON SIZE Nil ON MAXIMIZE Nil ON MINIMIZE Nil ON PAINT Nil BACKCOLOR Nil NOTIFYICON NIL NOTIFYTOOLTIP NIL ON NOTIFYCLICK Nil ON GOTFOCUS Nil ON LOSTFOCUS Nil ON SCROLLUP Nil ON SCROLLDOWN Nil ON SCROLLLEFT Nil ON SCROLLRIGHT Nil ON HSCROLLBOX Nil ON VSCROLLBOX Nil

    DEFINE BUTTON Button_1
        ROW    280
        COL    30
        WIDTH  100
        HEIGHT 28
        ACTION AddPict()
        CAPTION "Picture"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

    DEFINE BUTTON Button_2
        ROW    280
        COL    410
        WIDTH  100
        HEIGHT 28
        ACTION AddLabels()
        CAPTION "Labels"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

END WINDOW
        Main.Center
        Main.Activate

Return


FUNCTION addPict()

IF IsControlDefined ( "Image_1" , "Main" )
	Main.Image_1.Release
	RETURN
ENDIF

DEFINE IMAGE Image_1
	PARENT Main
        ROW    30
        COL    60
        WIDTH  420
        HEIGHT 220
        PICTURE "img.jpg"
        HELPID Nil
        VISIBLE .T.
        STRETCH .T.
        ACTION Nil
    END IMAGE

RETURN
****************************************************************
FUNCTION AddLabels()
Local i, cLabelName

Local isControl:=IsControlDefined ( "L_1" , "Main")

FOR i=1 TO 100
	cLabelName:='L_'+ALLTRIM(STR(i))

	IF isControl

		DoMethod("Main", cLabelName, "Release")

	ELSE

	
	    DEFINE LABEL &cLabelName 
		PARENT Main
	        ROW    30+(20*int(i/10))
        	COL    60+(40*(i%10))
	        WIDTH  30
        	HEIGHT 20
        	VALUE ALLTRIM(STR(i))
	        FONTNAME "Arial"
        	FONTSIZE 9
	        VISIBLE .T.
	    END LABEL
	ENDIF
NEXT i
RETURN
By the way, I noticed the strange behavior of the IsControlDefined function:
IsControlDefined ( cLabelName , "Main") does not return "true" for the label controls already defined :shock:

Code: Select all

FUNCTION AddLabels()
Local i, cLabelName

FOR i=1 TO 100
	cLabelName:='L_'+ALLTRIM(STR(i))

	IF IsControlDefined ( cLabelName , "Main")

		DoMethod("Main", cLabelName, "Release")

	ELSE
	
	    DEFINE LABEL &cLabelName 
		PARENT Main
	        ROW    30+(20*int(i/10))
        	COL    60+(40*(i%10))
	        WIDTH  30
        	HEIGHT 20
        	VALUE ALLTRIM(STR(i))
	        FONTNAME "Arial"
        	FONTSIZE 9
	        VISIBLE .T.
	    END LABEL
	ENDIF
NEXT i
RETURN


thank you edk worked perfect, I need now the label in the vertical position

Re: label at runtime

Posted: Wed Sep 06, 2017 2:49 am
by srvet_claudio
Try with:

IsControlDefined ( Image_1 , Main )

without quotes in the names of controls and windows

Re: label at runtime

Posted: Wed Sep 06, 2017 3:18 am
by jairpinho
srvet_claudio wrote:
Wed Sep 06, 2017 2:49 am
Try with:

IsControlDefined ( Image_1 , Main )

without quotes in the names of controls and windows
edk works as Mr Claudio explained IsControlDefined (Image_1, Main)
Thank you Claudio

Re: label at runtime

Posted: Wed Sep 06, 2017 7:14 am
by gfilatov
srvet_claudio wrote:
Wed Sep 06, 2017 2:49 am
Try with:

IsControlDefined ( Image_1 , Main )

without quotes in the names of controls and windows
Because IsControlDefined () is pseudo-function
Should be
FUNCTION addPict()

IF IsControlDefined ( Image_1 , Main )
...
and
FUNCTION AddLabels()
Local i, cLabelName

FOR i=1 TO 100
cLabelName:='L_'+ALLTRIM(STR(i))

IF _IsControlDefined ( cLabelName , "Main")
...

Re: label at runtime

Posted: Wed Sep 06, 2017 11:03 pm
by jairpinho
I need now the label in the vertical position

Re: label at runtime

Posted: Thu Sep 07, 2017 5:46 am
by mol
I've created my own label control with vertical center option, but I haven't found method to create vertical orientated label.
Maybe Claudio or Grigory knows if it's possible.

Re: label at runtime

Posted: Thu Sep 07, 2017 6:06 am
by edk
Maybe try use Claudio's bos taurus.

Re: label at runtime

Posted: Thu Sep 07, 2017 6:27 am
by mol
IMO, this is possible only using graphics tools.