pro2gramer5 Posted November 2, 2016 Share Posted November 2, 2016 Hello, I am trying to create a GUI that deletes and adds controls as users interact with it. The problem is that when a control is deleted, it's original Case statement is assigned to the next available control under the same class. In the example below, you will see that once the 1st two buttons are deleted and the 3rd and 4th buttons are created, clicking button 3 does the same thing that buton 1 was assigned to. Any suggestions on fixing the code or using an alternate method? I would rather not have to create a new GUI if I don't have to. Thanks expandcollapse popup#include <GUIConstants.au3> $hGUI = GUICreate (Default, Default, 500, 100) $idButton1 = GUICtrlCreateButton ("Button1", 10, 10, 50, 40) $idButton2 = GUICtrlCreateButton ("Button2", 50, 40, 50, 40) GUISetState (@SW_SHOW, $hGUI) Local $idDummy Local $idButton3 Local $idButton4 While 1 $idMsg = GUIGetMsg() Switch $idMsg Case $GUI_EVENT_CLOSE ExitLoop Case $idButton1 GUICtrlDelete ($idButton1) GUICtrlDelete ($idButton2) $idButton3 = GUICtrlCreateButton ("Button3", 20, 20, 50, 40) $idButton4 = GUICtrlCreateButton ("Button4", 60, 30, 50, 40) GUICtrlSetState ($idButton4, $GUI_DISABLE) Msgbox (0, "", "this is the original case function") Case $idButton2 GUICtrlDelete ($idButton1) GUICtrlDelete ($idButton2) $idButton3 = GUICtrlCreateButton ("Button3", 20, 20, 50, 40) $idButton4 = GUICtrlCreateButton ("Button4", 60, 30, 50, 40) $idCombo = GUICtrlCreateCombo ( 80, 40, 100, 40) GUICtrlSetState ($idButton4, $GUI_DISABLE) Case $idButton3 GUICtrlSetState ($idButton4, $GUI_ENABLE) EndSwitch WEnd GUIDelete ($hGUI) Link to comment Share on other sites More sharing options...
BrewManNH Posted November 2, 2016 Share Posted November 2, 2016 Perhaps building all the controls first, then hiding the ones you don't want to show at start up? Then you can hide/unhide them as you interact with the GUI. Use GUICtrlSetState to hide/unhide them. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
AutoBert Posted November 3, 2016 Share Posted November 3, 2016 Using the OnEventMode should work without this behaviour: expandcollapse popup#include <GUIConstants.au3> Opt("GUIOnEventMode", 1) ;0=disabled, 1=OnEvent mode enabled $hGUI = GUICreate(Default, Default, 500, 100) GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit') $idButton1 = GUICtrlCreateButton("Button1", 10, 10, 50, 40) GUICtrlSetOnEvent(-1, 'Button1Clicked') $idButton2 = GUICtrlCreateButton("Button2", 80, 10, 50, 40) GUICtrlSetOnEvent(-1, 'Button2Clicked') GUISetState(@SW_SHOW, $hGUI) Local $idDummy Local $idButton3 Local $idButton4 Local $iTop = 10 WinWaitClose($hGUI) _Exit Func Button1Clicked() $iTop += 30 GUICtrlDelete($idButton1) GUICtrlDelete($idButton2) $idButton3 = GUICtrlCreateButton("Button3", 10, $iTop, 50, 40) GUICtrlSetOnEvent(-1,'Button3clicked') $idButton4 = GUICtrlCreateButton("Button4", 80, $iTop, 50, 40) GUICtrlSetOnEvent(-1, 'Button4clicked') GUICtrlSetState(-1, $GUI_DISABLE) MsgBox(0, @GUI_CtrlId, "this is the original case function") EndFunc ;==>Button1Clicked Func Button2Clicked() $iTop += 30 GUICtrlDelete($idButton1) GUICtrlDelete($idButton2) $idButton3 = GUICtrlCreateButton("Button3", 10, $iTop, 50, 40) GUICtrlSetOnEvent(-1, 'Button3clicked') $idButton4 = GUICtrlCreateButton("Button4", 80, $iTop, 50, 40) GUICtrlSetOnEvent(-1, 'Button4clicked') GUICtrlSetState(-1, $GUI_DISABLE) $idCombo = GUICtrlCreateCombo(80, 40, 100, 40) EndFunc ;==>Button2Clicked Func Button3clicked() GUICtrlSetState($idButton4, $GUI_ENABLE) MsgBox(0,@GUI_CtrlId,'Button 3') EndFunc ;==>Button3clicked Func Button4clicked() GUICtrlSetState($idButton4, $GUI_ENABLE) MsgBox(0,@GUI_CtrlId,'Button 4') EndFunc ;==>Button3clicked Func _Exit() Exit GUIDelete($hGUI) EndFunc ;==>_Exit Link to comment Share on other sites More sharing options...
pro2gramer5 Posted November 3, 2016 Author Share Posted November 3, 2016 Gents, Both solutions seem viable, might go the OnEvent route for a cleaner code. Cheers! 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