[Gambas-user] How to address a text label created by code?
Jaap Cramer
jaap_cramer at ...67...
Thu Jan 24 22:18:14 CET 2008
Answer:
PUBLIC o AS Object[] ' public object to store your labels in
PUBLIC SUB Form_Open()
DIM sDir AS String
DIM tDirTL AS TextLabel
DIM iY AS Integer
o = NEW Object[]
FOR EACH sDir IN RDir("/home/yourplace/")
IF IsDir("/home/yourplace" &/ sDir) THEN
tDirTL = NEW TextLabel(ME.Scrollview1) AS "tDirLabel"
WITH tDirTL
.text = sDir
.height = 32
.width = 100
.X = ME.Scrollview1.X + 4
.Y = iY + 32
END WITH
o.Add(tDirTL) 'store all controls in a public object
iY = iY + 32 ' I moved this before the 'END IF', else, in my home, the space between would be to big :)
END IF
NEXT
END
PUBLIC SUB tDirLabel_Mousedown() ' you had the wrong mane here. tDirTL is just a local. you should use the name you gave it AS "NameOfControl"
DIM tDirTL AS TextLabel
FOR EACH tDirTL IN o ' check all labels in object O, and set label to NOT-BOLD
tDirTL.Font.Bold = FALSE
NEXT
LAST.font.bold = TRUE 'except for the last
END
This is maybe a quick-and-dirty method. you could also store the id (in object o[]) of the previous button. Now many buttons are set to NOT-BOLD, but they were already normal...
Well. I hope this helped you out!
Jaap
----------------------------------------
> Date: Thu, 24 Jan 2008 14:57:17 -0600
> From: m0e.lnx at ...626...
> To: gambas-user at lists.sourceforge.net
> Subject: [Gambas-user] How to address a text label created by code?
>
> I've been designing forms for a while now, and this is my second
> gambas application. In all other forms, I've always drawn the controls
> into the form, assign the properties, and handle events... all from
> the GUI.
> I decided to try to create a function to dynamically create
> components. The idea is to allow this application to be more
> expandable without modifying much of the code, so here is what I did.
>
> I have a form, in ther form there is a scrollview and an IconView
> I place some text labels on the scrollview. This gets triggered in the
> forms' Load event
>
> This function creates a Tex label for every directory in my $HOME dir.
> Each resulting text label enherit's it's own directory name.
>
> kinda like this
>
> PUBLIC SUB Form_Open()
> dim sDir as string
> dim tDirTL as TextLabel
> dim iY as integer
>
> FOR EACH sDir in RDir("/home/vluser")
> IF ISDIR("/home/vluser" &/ sDir) then
> tDirTL = new TextLabel(ME.Scrollview1) as "tDirLabel"
>
> WITH tDirTL
> .text = sDir
> .heigh = 32
> .width = 100
> .X = Me.Scrollview1.X + 4
> .Y = iY + 32
> END WITH
> end if
> iY = iY + 32
> NEXT
> END
>
> I can handle the events using LAST
>
> PUBLIC SUB tDirTL_Mousedown()
> Message.Info(LAST.Text & " was clicked")
> END
>
> Now, I want the label I click to turn it's label into Bold Lettering.
> I can do that using the font.bold = true property in the above SUB
>
> And here is my dilemma.
> I need every other label's Text to remain in plain lettering, and the
> Font.Bold to be applied only to the last label I click on.
>
> I've tried to set the font.bold = false but I can't find a way to
> address the other text labels...
>
> Using Gambas2-2.0.0. Any help is appreciated.
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
_________________________________________________________________
Bekijk Yes-R's real life soap op MSN Video!
http://video.msn.com/video.aspx?mkt=nl-nl&tab=m1192527562294&vid=8aff5b76-b78d-4b55-8b64-ef7e1d73aab2&playlist=videoByUuids:uuids:50b732c2-c105-41e9-adf0-36bd627d4eaa,0813da8c-031b-423f-a79d-35d925aee805,5cce447e-948d-43af-9862-45bb6bb9d6d8,6a39138c-f562-4254-be70-9d93343650f8,f9b8d78f-05a4-4c74-8e4b-28d20a4037ab&from=NLNL_Yes-R
More information about the User
mailing list