Jump to content

declare many labels at the same time


Recommended Posts

Hi there i want to set labels with the same background color if one label is active. 

like if $x = true then 

    GuiGUICtrlSetBkColor($lsong1, 0x000000)
    GUICtrlSetBkColor($lsong2, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetBkColor($lsong3, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetBkColor($lsong4, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetBkColor($lsong5, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetBkColor($lsong6, $GUI_BKCOLOR_TRANSPARENT)

   ..........

endif
must i do it like that ? or is there another way to do it.

if i have 50  Labels its getting annoying

Regards

Link to post
Share on other sites

Here one way. 

If True Then  ; some condition
  For $i = 1 To 50
    GUICtrlSetBkColor(Eval("lsong" & $i), $i = 1 ? 0x000000 : $GUI_BKCOLOR_TRANSPARENT) ; if $i = 1 black otherwise transparent
  Next
EndIf

I would suggest to use an Array for the creation instead of naming them individually :

#include <GUIConstants.au3>

GUICreate("")
Local $aLabel[50]
For $i = 0 To UBound($aLabel) - 1
  $aLabel[$i] = GUICtrlCreateLabel("Test", 10, 10+$i*20, 100, 15)
Next

GUISetState()

; some code goes here
Sleep (4000) ; for exmample only

If True Then  ; some condition
  For $i = 0 To UBound($aLabel) - 1
    GUICtrlSetBkColor($aLabel[$i], $i = 1 ? 0x000000 : $GUI_BKCOLOR_TRANSPARENT) ; if $i = 1 black otherwise transparent
  Next
EndIf

; some other code goes here
Sleep(4000) ; for example only

 

Edited by Nine
Link to post
Share on other sites

Just a brief note : @Hotzenplotz has asked this question simultaneously in the German forum too. 

To avoid duplication of work by possible helpers, here is the link : https://autoit.de/thread/87289-mehrere-labels-mit-gleichen-hintergrund-wenn-bedingung-erfüllt/

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites
1 minute ago, Hotzenplotz said:

sorry for this

It's not that bad at all, just a matter of etiquette ;)

The problem with crossposting is, that helpers spend their time without knowing about the respective responses in the other forum. Since we are all volunteers, time is precious and should not be wasted.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites
24 minutes ago, Musashi said:

The problem with crossposting is, that helpers spend their time without knowing about the respective responses in the other forum.

maybe polyglotonus cross-posting should be allowed if

  1. the poster is reasonably fluent in both languages
  2. the communities do not substantially overlap
  3. the poster communicates and translates relevant comments between groups

 

Code hard, but don’t hard code...

Link to post
Share on other sites
Posted (edited)
3 hours ago, Nine said:

Here one way. 

If True Then  ; some condition
  For $i = 1 To 50
    GUICtrlSetBkColor(Eval("lsong" & $i), $i = 1 ? 0x000000 : $GUI_BKCOLOR_TRANSPARENT) ; if $i = 1 black otherwise transparent
  Next
EndIf

this worked for me first caus it is easy to understand but u are right with the array, I must get firm more and more with it.

Thanks Mate

 

Edited by Hotzenplotz
Link to post
Share on other sites
40 minutes ago, JockoDundee said:

maybe polyglotonus cross-posting should be allowed if ...

I fully agree with you, that there are forms of crossposting that can be very useful (you've already named some). For example, there are nice scripts in the German forum (and in other country forums probably as well), that have never seen the light of day in the English forum (and vice versa). The reasons can be manifold. In some cases it fails due to lack of language skills, in others the author simply has no interest in it.

If someone takes the effort to present a script in other forums and even explain its functionality, it will be a benefit for the entire AutoIt community :).

However, regarding the source code, there should always be only one central download location. Otherwise, there might be different versions, and no one knows in the end which is the right one.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites
Posted (edited)
On 3/11/2021 at 8:51 PM, Nine said:

Here one way. 

I would suggest to use an Array for the creation instead of naming them individually :

#include <GUIConstants.au3>

GUICreate("")
Local $aLabel[50]
For $i = 0 To UBound($aLabel) - 1
  $aLabel[$i] = GUICtrlCreateLabel("Test", 10, 10+$i*20, 100, 15)
Next

GUISetState()

; some code goes here
Sleep (4000) ; for exmample only

If True Then  ; some condition
  For $i = 0 To UBound($aLabel) - 1
    GUICtrlSetBkColor($aLabel[$i], $i = 1 ? 0x000000 : $GUI_BKCOLOR_TRANSPARENT) ; if $i = 1 black otherwise transparent
  Next
EndIf

; some other code goes here
Sleep(4000) ; for example only

 

I have done it now like this, how to set label font colors and tips was easy for me, but how do i give every label an event with differnt  functions  

Edited by Hotzenplotz
Link to post
Share on other sites
Posted (edited)
23 hours ago, Hotzenplotz said:

I have done it now like this, how to set label font colors and tips was easy for me, but how do i give every label an event with differnt  functions  

i found out how to do it with using a array for the functions

  
Edited by Hotzenplotz
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...