DoubleMcLovin Posted July 21, 2010 Posted July 21, 2010 (edited) basically what I want to have, is a listbox with several options. Each of these options will change the value of the variable $text. The variable $text will be fed into a label(unless there is a better element to use?). Ex: with this window open I have the choices 1,2,3,4 in a listbox. A little to the left of the listbox there is text that alerts me which element I have selected. eg: "You have 1 selected!", "You have 2 selected!", "You have 3 selected!"... Any way this could be done? EDIT: Sorry, I am very new to GUIs.... Edited July 21, 2010 by DoubleMcLovin
Moderators Melba23 Posted July 21, 2010 Moderators Posted July 21, 2010 DoubleMcLovin,I think this is what you want: #include <GUIConstantsEx.au3> $sList = "Item 1|Item 2|Item 3|Item 4" $hGUI = GUICreate("Test", 500, 500) $hList = GUICtrlCreateList("", 10, 10, 200, 200) GUICtrlSetData($hList, $sList) $hLabel = GUICtrlCreateLabel("", 250, 10, 200, 20) GUISetState() $sCurrList = "" While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ;--------------------------------- $sActList = GUICtrlRead($hList) If $sActList <> $sCurrList Then $sCurrList = $sActList GUICtrlSetData($hLabel, "You have " & $sActList & " selected") EndIf ;--------------------------------- ;GUICtrlSetData($hLabel, "You have " & GUICtrlRead($hList) & " selected") WEndIf you are wondering why we have all the $aActList <> $sCurrList code, try commenting out the lines between ----------- and use just the simple GUICtrlSetData($hLabel... line. That should make it clear! I have deliberately not commented anything - try and understand what is going on and ask if there is anything that is not clear. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Yoriz Posted July 21, 2010 Posted July 21, 2010 (edited) #include <GUIConstantsEx.au3> Opt("MustDeclareVars", 1) _GUI() Func _GUI() Local $hForm1 = GUICreate("Form1", 252, 117, -1, -1) Local $hList1 = GUICtrlCreateList("", 8, 8, 121, 97) GUICtrlSetData(-1, "1. Choice One|2. Choice Two|3. Choice Three|4. Choice Four") Local $hLabel1 = GUICtrlCreateLabel("", 144, 48, 102, 17) GUISetState(@SW_SHOW) Local $sCurrentSelected, $sText While 1 Local $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $hList1 $sText = GUICtrlRead($hList1) If $sCurrentSelected <> "You have " & StringLeft($sText, 1) & " selected" Then GUICtrlSetData($hLabel1, "You have " & StringLeft($sText, 1) & " selected") EndIf EndSwitch WEnd EndFunc ;==>_Gui Edited July 21, 2010 by Yoriz GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
DoubleMcLovin Posted July 21, 2010 Author Posted July 21, 2010 DoubleMcLovin, I think this is what you want: #include <GUIConstantsEx.au3> $sList = "Item 1|Item 2|Item 3|Item 4" $hGUI = GUICreate("Test", 500, 500) $hList = GUICtrlCreateList("", 10, 10, 200, 200) GUICtrlSetData($hList, $sList) $hLabel = GUICtrlCreateLabel("", 250, 10, 200, 20) GUISetState() $sCurrList = "" While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ;--------------------------------- $sActList = GUICtrlRead($hList) If $sActList <> $sCurrList Then $sCurrList = $sActList GUICtrlSetData($hLabel, "You have " & $sActList & " selected") EndIf ;--------------------------------- ;GUICtrlSetData($hLabel, "You have " & GUICtrlRead($hList) & " selected") WEnd If you are wondering why we have all the $aActList <> $sCurrList code, try commenting out the lines between ----------- and use just the simple GUICtrlSetData($hLabel... line. That should make it clear! I have deliberately not commented anything - try and understand what is going on and ask if there is anything that is not clear. M23 Thanks for the help! I had actually just assumed I wouldn't get a response so early in the morning, so I went back to reading tutorials and help files. After about 3.5hrs I was able to successfully build this myself (though your code is certainly cleaner by far!) Here is what I ended up with, this is the entire window, which is just a rough draft, but there it is! expandcollapse popup#include <GUIConstants.au3> Global $CHName, $CHSex, $CHRace Local $RD, $RDInline $RDInline = "You Lose!" #Region ; Character Creation Screen $CHCreateForm = GUICreate("Create Your Character", 362, 325, 321, 212) GUICtrlCreateGroup("Name", 0, 0, 185, 41) $CHName = GUICtrlCreateInput("", 0, 16, 177, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateGroup("Sex", 0, 48, 185, 41) $CHSexMale = GUICtrlCreateRadio("Male", 16, 64, 65, 17) $CHSexFemale = GUICtrlCreateRadio("Female", 112, 64, 65, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateGroup("Race", 184, 0, 177, 265) $CHRace = GUICtrlCreateList("", 192, 16, 145, 240) GUICtrlSetData(-1, "Race1|Race2|Race3", "Race1") GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateGroup("Race Details", 0, 96, 185, 225) $RD = GUICtrlCreateLabel($RDInline, 8, 109, 140, 209) GUICtrlCreateGroup("", -99, -99, 1, 1) $Next = GUICtrlCreateButton("Next", 216, 280, 113, 33, 0) GUICtrlSetState($CHSexMale, $GUI_CHECKED) GUICtrlSetState($Next, $GUI_DEFBUTTON) #EndRegion ; Character Creation Screen $CHSex = "Male" ; Sets Male as the default sex GUISetState () While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $Next MsgBox(0, "Next", "You hit the button!" & @LF & $CHSex & @LF & $RD & @LF & $RDInline & @LF & $CHRace) Case $msg = $CHSexMale And BitAND(GUICtrlRead($CHSexMale), $GUI_CHECKED) = $GUI_CHECKED $CHSex = "Male" ; Changes sex to Male Case $msg = $CHSexFemale And BitAND(GUICtrlRead($CHSexFemale), $GUI_CHECKED) = $GUI_CHECKED $CHSex = "Female" ; Changes sex to Female Case $msg = $CHRace $RDInline = GUICtrlRead($CHRace) GUICtrlSetData($RD, $RDInline) EndSelect WEnd Being that this is my first attempt at a GUI, I am kinda happy with it. I figured making a simple game would be a great way to learn how to use the GUI controls.
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