mattw112 Posted May 9, 2007 Share Posted May 9, 2007 (edited) I'm createing a bunch of labels and setting their font. But later on in my script as I see something that matches the text on the label I want to make that specific label bold. How do I do this? Here's the code making the labels: ; Create Labels and Populate them with the contents from the ini file For $k=0 to $LABELS $PLabelNew = $PLabel & $k $TEXT = $AvailableArray[$tArrayItem + $k] $PLabelNew = GUICtrlCreateLabel( $TEXT , 30, $j , 260 , 60 ) GUICtrlSetFont ( -1, 9, 400, "", "Arial" ) $j+=20 Next I was going to try to make the $PLabelNew an array that matched the same $k as the text like this: $PlabelNew[$k] but when I tried this the debugger didn't like it?? Any other way? Like maybe scanning all the labels on the GUI (without knowing the controlids) and then seeing if their text matches a certain string? Thanks, Terry Edited May 9, 2007 by mattw112 Link to comment Share on other sites More sharing options...
enaiman Posted May 9, 2007 Share Posted May 9, 2007 (edited) Koda Form Designer from Scite-Options has a very good use You can experiment with it and find the needed code. In this case, to make a font bold you need to change the font weight 800 (default is 400) GUICtrlSetFont (controlID, size [, weight [, attribute [, fontname]]] ) I was going to try to make the $PLabelNew an array that matched the same $k as the text like this: $PlabelNew[$k] but when I tried this the debugger didn't like it?? I guess in order to use this $PlabelNew[$k] you will need first to declare it like: Dim $PlabelNew[30] ;or whatever the dimension is Edited May 9, 2007 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
mattw112 Posted May 9, 2007 Author Share Posted May 9, 2007 Koda Form Designer from Scite-Options has a very good use You can experiment with it and find the needed code.In this case, to make a font bold you need to change the font weight 800 (default is 400)I know how to make the label bold. That's not the issue. To make a label bold you need to know the controlid. That's my issue. I don't know all the control ids for all the labels I made from the first array.I need to be able to scan all the labels on the GUI and then see if any of them match a string, if they do then get the control id and make it bold.Terry Link to comment Share on other sites More sharing options...
enaiman Posted May 9, 2007 Share Posted May 9, 2007 I see .... OK - I've made a modification of your script and the result is here: Dim $PLabel[30] ;declare the array For $k=0 to $LABELS ;$PLabelNew = $PLabel & $k ;useless $TEXT = $AvailableArray[$tArrayItem + $k] $PLabel[$k] = GUICtrlCreateLabel( $TEXT , 30, $j , 260 , 60 ) GUICtrlSetFont ( -1, 9, 400, "", "Arial" ) $j+=20 Next For $k=0 to $LABELS Switch GUICtrlRead($PLabel[$k]) Case "Test1" ;if the content of the label is "Test1" GUICtrlSetFont ($PLabel[$k],9, 800, 1, "Arial") Case "Test2" ;if the content of the label is "Test2" or you can put anything else GUICtrlSetFont ($PLabel[$k],9, 400, 2, "Arial") EndSwitch Next Hope this answer your question SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
smashly Posted May 9, 2007 Share Posted May 9, 2007 In boredom here's my dodgey version for an example of finding a ctrl id from an array after it's created. Click on a label and it gives you the ctrl id and where in the array it is in a msg box. Also fills in the inputbox with the labels text after clicking ok. Hit the button to to set the label text bold if the input text is the same as the label text. Type in the label text into the input box manually if you prefer click button and if it matches a label text it makes it bold. expandcollapse popup#include <GuiConstants.au3> Global $LABELS[11], $TEXT[11] $TEXT[1] = 'Can I Find?' $TEXT[2] = 'Waht Am I looking for?' $TEXT[3] = 'Sky is Blue.... Sometimes' $TEXT[4] = 'far out brussel sprout?' $TEXT[5] = 'Sloppy Dot' $TEXT[6] = 'Fish Ahoy!!!!' $TEXT[7] = '54321' $TEXT[8] = '12345' $TEXT[9] = '1A2B3C' $TEXT[10] = 'Can I Find?' $y = 10 GuiCreate("Test") For $i = 1 to 10 $LABELS[$i] = GUICtrlCreateLabel($TEXT[$i] , 30, $y , 260 , 20 ) GUICtrlSetBkColor(-1, 0xffffff) GUICtrlSetFont ( -1, 9, 400, "", "Arial" ) $y = $y + 30 Next $Input = GUICtrlCreateInput('', 30, $y, 260, 20) $Button = GUICtrlCreateButton('Search for the text on a label', 30, $y + 30, 260, 30) GuiSetState() While 1 $msg = GuiGetMsg() For $c = 1 To 10 Select Case $msg = $LABELS[$c] For $n = 1 To 10 GUICtrlSetBkColor($LABELS[$n], 0xffffff) GUICtrlSetColor($LABELS[$n],0x000000) GUICtrlSetFont ($LABELS[$n], 9, 400, "", "Arial" ) Next GUICtrlSetBkColor($LABELS[$c], 0x000000) GUICtrlSetColor($LABELS[$c],0xffffff) GUICtrlSetFont ($LABELS[$c], 12, 700, "", "Arial" ) MsgBox(0,'', 'Ctrl ID: ' & $LABELS[$c] & @LF & 'Found in: $LABELS[' & $c & ']') GUICtrlSetData($Input, GuiCtrlRead($LABELS[$c])) GUICtrlSetBkColor($LABELS[$c], 0xffffff) GUICtrlSetColor($LABELS[$c],0x000000) GUICtrlSetFont ($LABELS[$c], 9, 400, "", "Arial" ) EndSelect Next Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $Button For $n = 1 To 10 GUICtrlSetBkColor($LABELS[$n], 0xffffff) GUICtrlSetColor($LABELS[$n],0x000000) GUICtrlSetFont ($LABELS[$n], 9, 400, "", "Arial" ) Next For $f = 1 To 10 If GUICtrlRead($Input) == GUICtrlRead($LABELS[$f]) Then GUICtrlSetBkColor($LABELS[$f], 0x000000) GUICtrlSetColor($LABELS[$f],0xffffff) GUICtrlSetFont ($LABELS[$f], 12, 700, "", "Arial" ) EndIf Next EndSelect WEnd You can see how board I get huh Cheers Link to comment Share on other sites More sharing options...
xcal Posted May 9, 2007 Share Posted May 9, 2007 (edited) expandcollapse popup#include <GUIConstants.au3> Opt('GuiOnEventMode', 1) GUICreate('', 230, 310) GUISetOnEvent($GUI_EVENT_CLOSE, 'quit') $input = GUICtrlCreateInput('Input Label Name', 120, 46, 100, 20) GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlCreateButton('Get Label', 120, 76, 100, 26) GUICtrlSetOnEvent(-1, 'disbyname') GUICtrlSetState(-1, $GUI_DEFBUTTON) GUICtrlCreateLabel('Put a label''s name in the input and click "Get Label," or click directly on a label. (eg. Label 7)', 120, 106, 100, 70, $SS_CENTER) Dim $lbl_handles[1] $lbl_handles[0] = GUICtrlCreateLabel('Label 0', 10, 10, 100, 20, $SS_CENTER + $SS_CENTERIMAGE + $SS_SUNKEN) GUICtrlSetOnEvent(-1, 'getctrlid') For $i = 1 To 9 ReDim $lbl_handles[UBound($lbl_handles) + 1] $lbl_handles[$i] = GUICtrlCreateLabel('Label ' & $i, 10, $i * 30 + 10, 100, 20, $SS_CENTER + $SS_CENTERIMAGE + $SS_SUNKEN) GUICtrlSetOnEvent(-1, 'getctrlid') Next GUISetState() While 1 Sleep(100) WEnd Func disbyname() Local $read = GUICtrlRead($input), $found = False For $i = 0 To UBound($lbl_handles) - 1 If $read = GUICtrlRead($lbl_handles[$i]) Then MsgBox(0, '', 'handle is ' & $lbl_handles[$i]) GUICtrlSetFont($lbl_handles[$i], 12, 700) $found = True EndIf Next If Not $found Then MsgBox(0, '', 'Label not found.') EndFunc Func getctrlid() Local $id = @GUI_CtrlId MsgBox(0, '', 'handle is ' & $id) GUICtrlSetFont($id, 12, 700) EndFunc Func quit() Exit EndFunc Edited May 9, 2007 by xcal How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
mattw112 Posted May 9, 2007 Author Share Posted May 9, 2007 Thanks guys I'll give these ideas a try this afternoon and report back! Terry Link to comment Share on other sites More sharing options...
mattw112 Posted May 9, 2007 Author Share Posted May 9, 2007 I see .... OK - I've made a modification of your script and the result is here: Dim $PLabel[30] ;declare the array For $k=0 to $LABELS ;$PLabelNew = $PLabel & $k ;useless $TEXT = $AvailableArray[$tArrayItem + $k] $PLabel[$k] = GUICtrlCreateLabel( $TEXT , 30, $j , 260 , 60 ) GUICtrlSetFont ( -1, 9, 400, "", "Arial" ) $j+=20 Next For $k=0 to $LABELS Switch GUICtrlRead($PLabel[$k]) Case "Test1" ;if the content of the label is "Test1" GUICtrlSetFont ($PLabel[$k],9, 800, 1, "Arial") Case "Test2" ;if the content of the label is "Test2" or you can put anything else GUICtrlSetFont ($PLabel[$k],9, 400, 2, "Arial") EndSwitch NextoÝ÷ Øz)zØb±©ìÁêò¢êê¹ë-ÿªê-y8ZK7Üuëayø«²Û¶Ü©àz̨ºg§¶*'yÖ¢÷µªíx0ØCm7èùZméwÑ©Ýzwb"¶ayø«²ÙÞÆÑh®Ø^±ç(ÚZ®Ûa¢è!#¬«â¬²ç¬"Ü(ºWdyê`¢)à¶èºmçè®Z(¥©ÝjÈv'm«b· .×!jx¶¢{hëÞ¯+ax"Ë^iÚë-¶¨ëaxÁ«%¢"è*r§çm«m¢Øb±«¢+Ø)½ÈÀÌØí¬ôÀѼÀÌØí1 1L($ÀÌØíIôU% ÑɱI ÀÌØíA1±lÀÌØít¤(%%ÀÌØíIôÀÌØíÑ1¥¹Q¡¸($%U% ÑɱMѽ¹Ð ÀÌØíA1±lÀÌØít°ä°àÀÀ°à°ÅÕ½ÐíÉ¥°ÅÕ½Ðì¤(%¹%)9áÐ This goes through all the number of labels and checks to see if they match the line I'm looking for, if it does then it changes the font. Terry Link to comment Share on other sites More sharing options...
enaiman Posted May 9, 2007 Share Posted May 9, 2007 That's great Terry - I'm happy to see that you figured it out. I couldn't give you a more specific solution because I didn't knew what information you need to find (that's why I used that Switch statement). SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now