label at runtime
Moderator: Rathinagiri
label at runtime
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
Hi.
Do you mean this behaviour?
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![Shocked :shock:](./images/smilies/icon_eek.gif)
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
IsControlDefined ( cLabelName , "Main") does not return "true" for the label controls already defined
![Shocked :shock:](./images/smilies/icon_eek.gif)
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
edk wrote: ↑Tue Sep 05, 2017 8:45 pm Hi.
Do you mean this behaviour?By the way, I noticed the strange behavior of the IsControlDefined function: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
IsControlDefined ( cLabelName , "Main") does not return "true" for the label controls already defined
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
- srvet_claudio
- Posts: 2193
- Joined: Thu Feb 25, 2010 8:43 pm
- Location: Uruguay
- Contact:
Re: label at runtime
Try with:
IsControlDefined ( Image_1 , Main )
without quotes in the names of controls and windows
IsControlDefined ( Image_1 , Main )
without quotes in the names of controls and windows
Re: label at runtime
edk works as Mr Claudio explained IsControlDefined (Image_1, Main)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
Thank you Claudio
Re: label at runtime
Because IsControlDefined () is pseudo-functionsrvet_claudio wrote: ↑Wed Sep 06, 2017 2:49 am Try with:
IsControlDefined ( Image_1 , Main )
without quotes in the names of controls and windows
Should be
andFUNCTION addPict()
IF IsControlDefined ( Image_1 , Main )
...
FUNCTION AddLabels()
Local i, cLabelName
FOR i=1 TO 100
cLabelName:='L_'+ALLTRIM(STR(i))
IF _IsControlDefined ( cLabelName , "Main")
...
Kind Regards,
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
Re: label at runtime
I need now the label in the vertical position
Re: label at runtime
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.
Maybe Claudio or Grigory knows if it's possible.
Re: label at runtime
Maybe try use Claudio's bos taurus.
Re: label at runtime
IMO, this is possible only using graphics tools.