Sign in to follow this  
Followers 0
gcue

window with dynamic controls

9 posts in this topic

depending on the radio button chosen, id like to change the controls of the same window..

trying to do it through the while loop, the controls keep flickering

better way to do this?

thanks

GUICreate($version, 240, 100)

$check1 = GUICtrlCreateRadio("opt1", 10, 20)
$check2 = GUICtrlCreateRadio("opt2", 10, 40)
$check3 = GUICtrlCreateRadio("opt3", 10, 60)

GUISetOnEvent($GUI_EVENT_CLOSE, "Xbutton")

GUISetState(@SW_SHOW)

While 1
    ;Sleep(1)
    If BitAND(GUICtrlRead($check1), $GUI_CHECKED) = $GUI_CHECKED Then
        option1()
    EndIf
WEnd

Func option1()

    GUICtrlCreateLabel("option1", 120, 10)
    GUICtrlCreateButton("opt1", 120, 40)

EndFunc   ;==>option1

Share this post


Link to post
Share on other sites



gcue,

Use a flag to show if the controls are already created, that way you do not get the flashing:

#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)  ; <<<<<<<<<<<<<<<<<<<< Added

GUICreate("version", 240, 100)  ; <<<<<<<<<<<<<<<< Altered

$check1 = GUICtrlCreateRadio("opt1", 10, 20)
$check2 = GUICtrlCreateRadio("opt2", 10, 40)
$check3 = GUICtrlCreateRadio("opt3", 10, 60)

GUISetOnEvent($GUI_EVENT_CLOSE, "Xbutton")

GUISetState(@SW_SHOW)

$fOpt1Flag = False

While 1
    ;Sleep(1)
    If BitAND(GUICtrlRead($check1), $GUI_CHECKED) = $GUI_CHECKED Then
        If $fOpt1Flag = False Then option1()  ; <<<<<<<  Solution
    EndIf
WEnd

Func option1()

    $fOpt1Flag = True  ; <<<<<<<  Solution

    GUICtrlCreateLabel("option1", 120, 10)
    GUICtrlCreateButton("opt1", 120, 40)

EndFunc   ;==>option1

Func Xbutton()      ; <<<<<<<<<<<<<<<<<<<<<<<< Whole function added
    Exit        ; <<<<<<<<<<<<<<<<<<<<<<<< Whole function added
EndFunc    ; <<<<<<<<<<<<<<<<<<<<<<<< Whole function added

M23

Hint to any readers: If you post code which can be run directly without having to add half a dozen lines it really increases your chances of getting a quick response. :)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

works great when you switch the first time.. but when you switch back to it, it doesnt work

#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)  ; <<<<<<<<<<<<<<<<<<<< Added

GUICreate("version", 240, 100)  ; <<<<<<<<<<<<<<<< Altered

$check1 = GUICtrlCreateRadio("1", 10, 20, 20)
$check2 = GUICtrlCreateRadio("2", 10, 40, 20)
$check3 = GUICtrlCreateRadio("3", 10, 60, 20)

GUISetOnEvent($GUI_EVENT_CLOSE, "Xbutton")

GUISetState(@SW_SHOW)

$fOpt1Flag = False
$fOpt2Flag = False
$fOpt3Flag = False

While 1
    ;Sleep(1)
    If BitAND(GUICtrlRead($check1), $GUI_CHECKED) = $GUI_CHECKED Then
        If $fOpt1Flag = False Then option1()  ; <<<<<<<  Solution
    EndIf
    
    If BitAND(GUICtrlRead($check2), $GUI_CHECKED) = $GUI_CHECKED Then
        If $fOpt2Flag = False Then option2()  ; <<<<<<<  Solution
    EndIf
    
    If BitAND(GUICtrlRead($check3), $GUI_CHECKED) = $GUI_CHECKED Then
        If $fOpt3Flag = False Then option3()  ; <<<<<<<  Solution
    EndIf
WEnd

Func option1()

    $fOpt1Flag = True  ; <<<<<<<  Solution

    GUICtrlCreateLabel("option1", 120, 10)
    GUICtrlCreateButton("opt1", 120, 40)
    
    ;$fOpt1Flag = False

EndFunc   ;==>option1

Func option2()

    $fOpt2Flag = True  ; <<<<<<<  Solution

    GUICtrlCreateLabel("option2", 120, 10)
    GUICtrlCreateButton("opt2", 120, 40)
    
    ;$fOpt2Flag = False

EndFunc   ;==>option1

Func option3()

    $fOpt3Flag = True  ; <<<<<<<  Solution

    GUICtrlCreateLabel("option3", 120, 10)
    GUICtrlCreateButton("opt3", 120, 40)
    
    ;$fOpt3Flag = False

EndFunc   ;==>option1

Func Xbutton()      ; <<<<<<<<<<<<<<<<<<<<<<<< Whole function added
    Exit        ; <<<<<<<<<<<<<<<<<<<<<<<< Whole function added
EndFunc    ; <<<<<<<<<<<<<<<<<<<<<<<< Whole function added

Share this post


Link to post
Share on other sites

gcue,

I have given you a generic solution. So why do you not have a go at coding something yourself and come back if you have problems, rather than expecting me to give you a ready-coded snippet? :)

M23

Hint: You know that the flag idea works - what you have to do is delete the controls and reset the flag if the radio is not checked.


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

i did try. instead of just one option i added two more, i set the flags to false..and i also tried setting them back to true.. which brings back the flicker =)

still trying..

thanks for your original post =)

Edited by gcue

Share this post


Link to post
Share on other sites

still trying..

We agree that you are still trying... :)

I know you've been given examples like this before. And you've been around here too long to still be asking the same questions. It's time to study the examples and actually learn how they work:

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Global $iCheckboxes = 0
Do
    $iCheckboxes = Number(InputBox("Test", "Enter number of checkboxes\buttons: "))
Until $iCheckboxes <> 0

Global $hGUI, $avCheckboxes[$iCheckboxes], $avButtons[$iCheckboxes]

$hGUI = GUICreate("version", 300, 20 + (50 * $iCheckboxes))
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")

For $n = 0 To UBound($avCheckboxes) - 1
    $avCheckboxes[$n] = GUICtrlCreateCheckbox("Checkbox: " & $n + 1, 20, 20 + ($n * 50), 120, 20)
    GUICtrlSetOnEvent(-1, "_CheckBoxHit")
    $avButtons[$n] = GUICtrlCreateButton("Button: " & $n + 1, 175, 20 + ($n * 50), 100, 30)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetState(-1, $GUI_HIDE)
    GUICtrlSetOnEvent(-1, "_ButtonHit")
Next
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
WEnd

Func _CheckBoxHit()
    ; Set conditions
    For $n = 0 To UBound($avCheckboxes) - 1
        If ControlCommand($hGUI, "", $avCheckboxes[$n], "IsChecked") Then
            GUICtrlSetState($avButtons[$n], $GUI_SHOW)
            GUICtrlSetState($avButtons[$n], $GUI_ENABLE)
        Else
            GUICtrlSetState($avButtons[$n], $GUI_DISABLE)
            GUICtrlSetState($avButtons[$n], $GUI_HIDE)
        EndIf
    Next
EndFunc   ;==>_CheckBoxHit

Func _ButtonHit()
    ConsoleWrite("Debug:  _ButtonHit():  @GUI_CtrlId = " & @GUI_CtrlId & @LF)
    Local $sText = GUICtrlRead(@GUI_CtrlId)
    MsgBox(64, "Button Hit", "You clicked: " & $sText)
EndFunc   ;==>_ButtonHit

Func _Quit()
    Exit
EndFunc   ;==>_Quit

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

for the record, i dont remmeber asking for this before.

also, im not a programmer by any means

i have gotten better at this and am still working at improving.

after my sign on date, i didnt use autoit (or any other type of programming) for a few years and then started using it maybe just short of 2 years ago again

im sorry if i frustrate you.. this might come easy to some of you but not all of us.

anyway, thanks for your help PSalty/Melba =)

Edited by gcue

Share this post


Link to post
Share on other sites

gcue,

One way of doing it:

#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)

GUICreate("version", 240, 100)

$check1 = GUICtrlCreateRadio("opt1", 10, 20)
$check2 = GUICtrlCreateRadio("opt2", 10, 40)
$check3 = GUICtrlCreateRadio("opt3", 10, 60)

GUISetOnEvent($GUI_EVENT_CLOSE, "Xbutton")

GUISetState(@SW_SHOW)

Global $fOpt1Flag = False
Global $hLabel1 = 0
Global $hButton1 = 0
Global $fOpt2Flag = False
Global $hLabel2 = 0
Global $hButton2 = 0
Global $fOpt3Flag = False
Global $hLabel3 = 0
Global $hButton3 = 0

While 1
    For $i = $check1 To $check3
        If BitAND(GUICtrlRead($i), $GUI_CHECKED) = $GUI_CHECKED Then
            ConsoleWrite($i - $check1 + 1 & @CRLF)
            option($i - $check1 + 1)
            ExitLoop
        EndIf
    Next
WEnd

Func option($i)

    Switch $i
        Case 1
            If $fOpt1Flag = False Then
                GUICtrlDelete($hLabel2)
                GUICtrlDelete($hButton2)
                $fOpt2Flag = False
                GUICtrlDelete($hLabel3)
                GUICtrlDelete($hButton3)
                $fOpt3Flag = False
                $hLabel1 = GUICtrlCreateLabel("option1", 120, 10)
                $hButton1 = GUICtrlCreateButton("opt1", 120, 40)
                $fOpt1Flag = True
            EndIf
        Case 2
            If $fOpt2Flag = False Then
                GUICtrlDelete($hLabel1)
                GUICtrlDelete($hButton1)
                $fOpt1Flag = False
                GUICtrlDelete($hLabel3)
                GUICtrlDelete($hButton3)
                $fOpt3Flag = False
                $hLabel2 = GUICtrlCreateLabel("option2", 120, 10)
                $hButton2 = GUICtrlCreateButton("opt2", 120, 40)
                $fOpt2Flag = True
            EndIf
        Case 3
            If $fOpt3Flag = False Then
                GUICtrlDelete($hLabel1)
                GUICtrlDelete($hButton1)
                $fOpt1Flag = False
                GUICtrlDelete($hLabel2)
                GUICtrlDelete($hButton2)
                $fOpt2Flag = False
                $hLabel3 = GUICtrlCreateLabel("option3", 120, 10)
                $hButton3 = GUICtrlCreateButton("opt3", 120, 40)
                $fOpt3Flag = True
            EndIf
    EndSwitch

EndFunc   ;==>option1

Func Xbutton()
    Exit
EndFunc

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

thanks again melba =)

Share this post


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
Sign in to follow this  
Followers 0