Jump to content

Update GUI screen when radio button is clicked


Recommended Posts

In a GUI screen, I want to make 3 groups with 3 choices each. I want them to all be independent (somewhat). What I mean by that is I only want 1 choice to be allowed in each group, but I also want what is clicked in the one group to affect what is in the other groups.

So, I would have something basically like:

Group 1      Group 2         Group 3
-------      -------         -------

Choice 1 x    Choice 1      Choice 1

Choice 2        Choice 2        Choice 2 x

Choice 3        Choice 3 x    Choice 3

Now, if Choice 1 is clicked in Group 1, it could not be clicked in Group 2 or Group 3. If Choice 2 is clicked in Group 3, it couldn't be clicked in Group 1 or Group 2. Etc.

I know how to do this to update the variables, but how would you make those changes show on the screen immediately (or almost immediately)? Or can that be done at all?

If you can, all I need (hopefully) is to be pointed in the right direction of a function/command/whatever that I can look at, and then I will probably be able to go on from there.

Link to comment
Share on other sites

If you can, all I need (hopefully) is to be pointed in the right direction of a function/command/whatever that I can look at, and then I will probably be able to go on from there.

Styler001,

You may want to look at GUIDelete and then redraw the new window with its new settings.

I hope other more experienced users have some other suggestions because this is something I looking to do also.

taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Link to comment
Share on other sites

was pissing me off finally figured it out, accidently put my $msg = Guigetmsg() on the inside of the for loop instead of outside :D, this is going to be a lil complicated for you but it will be good learning, it uses a For loop with arrays , so it will reduce your amount of code , now its not very complicated it just disables the option straight across from it but eh its late

EDIT: since i was bored and am home alone i threw in so it wouldnt just do the one right across from it , but i did it the old fashion way

#include <GUIConstants.au3>
Global $a[4]
Global $b[4]
$Form1 = GUICreate("AForm1", 190, 131, 192, 125)
GUICtrlCreateLabel("Group 1", 16, 16, 42, 17)
$a[1] = GUICtrlCreateCheckbox("Choice 1 Group 1", 32, 48, 17, 17)
$a[2] = GUICtrlCreateCheckbox("Choice 2 Group 1", 32, 72, 17, 17)
$a[3] = GUICtrlCreateCheckbox("Choice 3 Group 1", 32, 96, 17, 17)
GUICtrlCreateLabel("Group 2", 96, 16, 42, 17)
$b[1] = GUICtrlCreateCheckbox("Choice 1 Group 2", 112, 48, 17, 17)
$b[2] = GUICtrlCreateCheckbox("Choice 2 Group 2", 112, 72, 17, 17)
$b[3] = GUICtrlCreateCheckbox("Choice 3 Group 2", 112, 96, 17, 17)
GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
For $i = 1 to 3
If $msg = $a[$i] Then
    If GUICtrlRead($a[$i]) = $GUI_CHECKED Then
    GUICtrlSetState($b[$i],$GUI_DISABLE)
    Elseif GUICtrlRead($a[$i]) = $GUI_UNCHECKED Then
    GUICtrlSetState($b[$i],$GUI_ENABLE)
    EndIf
EndIf
Next
WEnd
Edited by thatsgreat2345
Link to comment
Share on other sites

That's not quite what I had in mind. In that code, if I select Choice 2 I can still uncheck it or check Choice 1 without unchecking 2 first. But as soon as I check Choice 1, I can't select Choice 2 without first unchecking Choice 1. What I'd like is if Choice 1 is checked and I change my mind, I'd like to be able to just check Choice 2 or 3 without having to uncheck 1. I don't really want the other choices completely disabled.

(Alot of checking and unchecking there. Confused? :D)

Link to comment
Share on other sites

what im pickin up here is u just want it to check, well with some simple research through the help file, (but in my head), u just change enable/disable to check/unchecked

#include <GUIConstants.au3>
Global $a[4]
Global $b[4]
$Form1 = GUICreate("AForm1", 190, 131, 192, 125)
GUICtrlCreateLabel("Group 1", 16, 16, 42, 17)
$a[1] = GUICtrlCreateCheckbox("Choice 1 Group 1", 32, 48, 17, 17)
$a[2] = GUICtrlCreateCheckbox("Choice 2 Group 1", 32, 72, 17, 17)
$a[3] = GUICtrlCreateCheckbox("Choice 3 Group 1", 32, 96, 17, 17)
GUICtrlCreateLabel("Group 2", 96, 16, 42, 17)
$b[1] = GUICtrlCreateCheckbox("Choice 1 Group 2", 112, 48, 17, 17)
$b[2] = GUICtrlCreateCheckbox("Choice 2 Group 2", 112, 72, 17, 17)
$b[3] = GUICtrlCreateCheckbox("Choice 3 Group 2", 112, 96, 17, 17)
GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
For $i = 1 to 3
If $msg = $a[$i] Then
    If GUICtrlRead($a[$i]) = $GUI_CHECKED Then
        If $i = 1 Then
        GUICtrlSetState($b[2],$GUI_CHECKED)
        Elseif $i = 2 Then
        GUICtrlSetState($b[3],$GUI_CHECKED)
        Elseif $i = 3 Then
        GUICtrlSetState($b[1],$GUI_CHECKED)
        EndIf
    Elseif GUICtrlRead($a[$i]) = $GUI_UNCHECKED Then
        If $i = 1 Then
        GUICtrlSetState($b[2],$GUI_UNCHECKED)
        Elseif $i = 2 Then
        GUICtrlSetState($b[3],$GUI_UNCHECKED)
        Elseif $i = 3 Then
        GUICtrlSetState($b[1],$GUI_UNCHECKED)
        EndIf
    EndIf
EndIf
Next
WEnd
Link to comment
Share on other sites

  • Moderators

I was looking this over a bit, is this the effect your looking for?:

#include <GUIConstants.au3>
Global $a[4], $b[4], $c[4]
$Form1 = GUICreate("AForm1", 240, 131, 192, 125)
GUICtrlCreateLabel("Group 1", 16, 16, 42, 17)
For $i = 1 To UBound($a) - 1
    $a[$i] = GUICtrlCreateCheckbox("", 32, 24+($i*24), 17, 17)
Next
GUICtrlCreateLabel("Group 2", 96, 16, 42, 17)
For $i = 1 To UBound($b) - 1
    $b[$i] = GUICtrlCreateCheckbox("", 112, 24+($i*24), 17, 17)
Next
GUICtrlCreateLabel("Group 3", 176, 16, 42, 17)
For $i = 1 To UBound($c) - 1
    $c[$i] = GUICtrlCreateCheckbox("", 192, 24+($i*24), 17, 17)
Next

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
    For $i = 1 to UBound($a) - 1
        If $msg = $a[$i] Then
            If BitAND(GUICtrlRead($a[$i]), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($b[$i], $GUI_UNCHECKED)
                GUICtrlSetState($c[$i], $GUI_UNCHECKED)
            EndIf
        EndIf
        If $msg = $b[$i] Then
            If BitAND(GUICtrlRead($b[$i]), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($a[$i], $GUI_UNCHECKED)
                GUICtrlSetState($c[$i], $GUI_UNCHECKED)
            EndIf
        EndIf
        If $msg = $c[$i] Then
            If BitAND(GUICtrlRead($c[$i]), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($a[$i], $GUI_UNCHECKED)
                GUICtrlSetState($b[$i], $GUI_UNCHECKED)
            EndIf
        EndIf
    Next
WEnd

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

what im pickin up here is u just want it to check, well with some simple research through the help file, (but in my head), u just change enable/disable to check/unchecked

That lets me check any box without restrictions. And, actually, it started checking other boxes that I didn't want checked.

I was looking this over a bit, is this the effect your looking for?:

That's closer, but not quite the results I wanted either. While it will let only one box be checked horizontally, it still allows others in the same group to be checked vertically. I need for it to restrict it to only one choice per group as well.

This looks like it might be alot scarier than I thought it might be. :D

Edited by Styler001
Link to comment
Share on other sites

I know how to do this to update the variables, but how would you make those changes show on the screen immediately (or almost immediately)? Or can that be done at all?

If you can, all I need (hopefully) is to be pointed in the right direction of a function/command/whatever that I can look at, and then I will probably be able to go on from there.

Here are functions for Repaint GUI control or whole GUI form:

$control_hWnd = ControlGetHandle("","",$control_id)
DLLCall("user32.dll","int","InvalidateRect","hwnd",$control_hWnd,"int",0,"int",0) ; bErase=False
oÝ÷ Ù«­¢+ØÀÌØí½É´ÄôU%
ÉÑ ÅÕ½ÐìÅÕ½Ðì°ÔÀÀ°ÌÀÀ¤)±±
±° ÅÕ½ÐíÕÍÈÌȹ±°ÅÕ½Ðì°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°ÅÕ½Ðí%¹Ù±¥ÑIÐÅÕ½Ðì°ÅÕ½Ðí¡Ý¹ÅÕ½Ðì°ÀÌØí½É´Ä°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°À°ÅÕ½Ðí¥¹ÐÅÕ½Ðì°Ä¤ì±ÁIÐõ¹Õ±°ÉÍõQÉÕ
Link to comment
Share on other sites

  • Moderators

That lets me check any box without restrictions. And, actually, it started checking other boxes that I didn't want checked.

That's closer, but not quite the results I wanted either. While it will let only one box be checked horizontally, it still allows others in the same group to be checked vertically. I need for it to restrict it to only one choice per group as well.

This looks like it might be alot scarier than I thought it might be. :D

I'm curious if you have even done anything to try and help yourself. I mean, you see how the code went to block everything horizontally ... If you want it to also be group specific, is it that hard to try and manipulate what it was that was working horizontall for that task?

Edit:

#include <GUIConstants.au3>
Global $a[4], $b[4], $c[4]
$Form1 = GUICreate("AForm1", 240, 131, 192, 125)
GUICtrlCreateLabel("Group 1", 16, 16, 42, 17)
For $i = 1 To UBound($a) - 1
    $a[$i] = GUICtrlCreateCheckbox("", 32, 24+($i*24), 17, 17)
Next
GUICtrlCreateLabel("Group 2", 96, 16, 42, 17)
For $i = 1 To UBound($b) - 1
    $b[$i] = GUICtrlCreateCheckbox("", 112, 24+($i*24), 17, 17)
Next
GUICtrlCreateLabel("Group 3", 176, 16, 42, 17)
For $i = 1 To UBound($c) - 1
    $c[$i] = GUICtrlCreateCheckbox("", 192, 24+($i*24), 17, 17)
Next

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
    For $i = 1 to UBound($a) - 1
        If $msg = $a[$i] Then
            If BitAND(GUICtrlRead($a[$i]), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($b[$i], $GUI_UNCHECKED)
                GUICtrlSetState($c[$i], $GUI_UNCHECKED)
                If $i = 3 Then
                    GUICtrlSetState($a[1], $GUI_UNCHECKED)
                    GUICtrlSetState($a[2], $GUI_UNCHECKED)
                ElseIf $i = 2 Then
                    GUICtrlSetState($a[1], $GUI_UNCHECKED)
                    GUICtrlSetState($a[3], $GUI_UNCHECKED)
                Else
                    GUICtrlSetState($a[2], $GUI_UNCHECKED)
                    GUICtrlSetState($a[3], $GUI_UNCHECKED)
                EndIf
            EndIf
        EndIf
        If $msg = $b[$i] Then
            If BitAND(GUICtrlRead($b[$i]), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($a[$i], $GUI_UNCHECKED)
                GUICtrlSetState($c[$i], $GUI_UNCHECKED)
                If $i = 3 Then
                    GUICtrlSetState($b[1], $GUI_UNCHECKED)
                    GUICtrlSetState($b[2], $GUI_UNCHECKED)
                ElseIf $i = 2 Then
                    GUICtrlSetState($b[1], $GUI_UNCHECKED)
                    GUICtrlSetState($b[3], $GUI_UNCHECKED)
                Else
                    GUICtrlSetState($b[2], $GUI_UNCHECKED)
                    GUICtrlSetState($b[3], $GUI_UNCHECKED)
                EndIf
            EndIf
        EndIf
        If $msg = $c[$i] Then
            If BitAND(GUICtrlRead($c[$i]), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($a[$i], $GUI_UNCHECKED)
                GUICtrlSetState($b[$i], $GUI_UNCHECKED)
                If $i = 3 Then
                    GUICtrlSetState($c[1], $GUI_UNCHECKED)
                    GUICtrlSetState($c[2], $GUI_UNCHECKED)
                ElseIf $i = 2 Then
                    GUICtrlSetState($c[1], $GUI_UNCHECKED)
                    GUICtrlSetState($c[3], $GUI_UNCHECKED)
                Else
                    GUICtrlSetState($c[2], $GUI_UNCHECKED)
                    GUICtrlSetState($c[3], $GUI_UNCHECKED)
                EndIf
            EndIf
        EndIf
    Next
WEnd
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Here, this should really confuse the hell out of you:

#include <GUIConstants.au3>
Global $a[4], $b[4], $c[4]
$Form1 = GUICreate("AForm1", 240, 131, 192, 125)
GUICtrlCreateLabel("Group 1", 16, 16, 42, 17)
For $i = 1 To UBound($a) - 1
    $a[$i] = GUICtrlCreateCheckbox("", 32, 24+($i*24), 17, 17)
Next
GUICtrlCreateLabel("Group 2", 96, 16, 42, 17)
For $i = 1 To UBound($b) - 1
    $b[$i] = GUICtrlCreateCheckbox("", 112, 24+($i*24), 17, 17)
Next
GUICtrlCreateLabel("Group 3", 176, 16, 42, 17)
For $i = 1 To UBound($c) - 1
    $c[$i] = GUICtrlCreateCheckbox("", 192, 24+($i*24), 17, 17)
Next

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
    For $i = 1 to UBound($a) - 1
        If $msg = $a[$i] Then
            If BitAND(GUICtrlRead($a[$i]), $GUI_CHECKED) = $GUI_CHECKED Then
                _ControlCheckBox('a', $i)
            EndIf
        EndIf
        If $msg = $b[$i] Then
            If BitAND(GUICtrlRead($b[$i]), $GUI_CHECKED) = $GUI_CHECKED Then
                _ControlCheckBox('b', $i)
            EndIf
        EndIf
        If $msg = $c[$i] Then
            If BitAND(GUICtrlRead($c[$i]), $GUI_CHECKED) = $GUI_CHECKED Then
                _ControlCheckBox('c', $i)
            EndIf
        EndIf
    Next
WEnd

Func _ControlCheckBox($sControl, $iElement)
    Local $Array1 = '', $Array2 = '', $Array3 = ''
    If $sControl = 'a' Then 
        $Array1 = $a
        $Array2 = $b
        $Array3 = $c
    ElseIf $sControl = 'b' Then
        $Array1 = $b
        $Array2 = $a
        $Array3 = $c
    Else
        $Array1 = $c
        $Array2 = $a
        $Array3 = $b
    EndIf
    If BitAND(GUICtrlRead($Array1[$iElement]), $GUI_CHECKED) = $GUI_CHECKED Then
        GUICtrlSetState($Array2[$iElement], $GUI_UNCHECKED)
        GUICtrlSetState($Array3[$iElement], $GUI_UNCHECKED)
        If $iElement = 3 Then
            GUICtrlSetState($Array1[1], $GUI_UNCHECKED)
            GUICtrlSetState($Array1[2], $GUI_UNCHECKED)
        ElseIf $iElement = 2 Then
            GUICtrlSetState($Array1[1], $GUI_UNCHECKED)
            GUICtrlSetState($Array1[3], $GUI_UNCHECKED)
        Else
            GUICtrlSetState($Array1[2], $GUI_UNCHECKED)
            GUICtrlSetState($Array1[3], $GUI_UNCHECKED)
        EndIf
    EndIf
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I'm curious if you have even done anything to try and help yourself.

Was that comment really necessary? Some of us haven't been at this as long as you seem to have been. And I only come here as a last resort when I can't figure something out myself. Maybe it being late at night when I read the replies didn't help much. In general, people are usually pretty considerate of others when they help here. Try and be a little more understanding and realize we don't all have your intellect.

If I'd been able to find an answer using search, I wouldn't have even bothered you with this. I've only asked for help here twice, and the first time I actually figured out what I needed to do after I'd posted my question.

As I'd said in my first post, I was just asking for a direction to head in. Am I supposed to come back here and say, "Yeah, that works just like I was asking for it to," when it doesn't? Wouldn't that be a little misleading for the next person that might have the same question. (In fact, taurus905 did want to know how to do this same exact thing.)

I apologize all to hell for asking for help when I don't understand something. If this reply has offended you, well, you've got company because your reply was pretty condescending, too.

Link to comment
Share on other sites

  • Moderators

I apologize all to hell for asking for help when I don't understand something. If this reply has offended you, well, you've got company because your reply was pretty condescending, too.

Nope, this reply didn't really offend me...

This one kind of got under my skin is why I posted what I posted.

That's closer, but not quite the results I wanted either.

I don't really care if your new or not... you showed no effort. Yeah, you haven't been around as long as me, and I stumbled through everything there was, but I never stopped trying. I still stumble through quite a bit...

If I had really wanted to be an ass, would I have posted the answer (twice even)?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I really do appreciate your help with this and I apologize for my remarks. Like I said before, I was looking at the replies late at night and my thought processes probably weren't running at full speed (which probably also wasn't a good time to make my reply). When I commented that the results weren't what I was looking for, I didn't mean for you to go back and try something else. I was just trying to point out that that wasn't what I had in mind and was trying to clarify.

I really do enjoy tackling this stuff on my own as much as I can, but I just couldn't figure out where to look in the help and couldn't find anything similar to this in my search here. I really was just looking for a nudge in the right direction, and now, looking more closely at your script, I would never have thought of the BitAND route. I still don't understand how/what that does.

And, yes, your last two examples do exactly what I was looking for. It's going to take me some time to sift through that and understand what it's doing before I can consider incorporating something like that. Believe it or not, I do like to have a handle on what I'm using, and not just come begging for someone to do my work for me. And I do like to do as much of the work myself if I can. But, at times, I am genuinely stuck. I'm just proud of myself for getting a grasp on arrays and how significantly they had shortened an extremely long and ugly script I'd made.

Again, thanks for your help.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...