Jump to content

Probably a basic question; Build a gui upon button click


WJST
 Share

Recommended Posts

Hi,

I go a question, probably a pretty easy and/or dumb one, but still; can't figure it out...

Here it is;

I go myself a cute little gui, containing a button;

The button is $but1. But1 creates a new button, $but2:

Case $but1
          $but2 = GUICtrlCreateButton("button2", 400, 696, 97, 65)
                 Case $but2

This doesnt work. It simply exits with a variable undeclined warning, which is obvious, since I only create the button upon but1 click.

Is it nessecary to define $but2 somewhere before or how can I do this?

Maybe I should make the question a bit different; more to the point:

I want to create a GUI, which changes when clicked. So all elements on it should be removed and new elements should be places. How can I do this easily?

Who can help this beginner out?

Thanks!

(ps, very shamefull, 2 stupid typo's in the title.. cant edit it..)

; --------------------------------------------------------------------

Edited by Melba23 to correct the title as you need 5 posts to get the "Edit" button. To edit the title you need to select the "Use Full Editor" option while editing the first post. :)

Edited by Melba23
Link to comment
Share on other sites

Im first off going to assume that you had already started the switch, inside a loop, and are testing the guigetmsg() function.

So the problem would be that, if your program runs through the switch, it will test

Case $but2

if you had not clicked on the first button by then, $but2 would not exist, and so it will throw an error. what you could do to solve that is just to create

Global $but2 = 15000

or something like that, just so that autoit will recognize that yes, the variable exists, but as we are testing guigetmsg(), it is not 15000.

dont do that, though, its kind of a bad way to get around it, i would say. just create $but2 from the start, but set its state as hidden. then, when you are running through case $but1 in the switch, do

GUICtrlSetState ($but2, $GUI_SHOW)

so all in all, it would be something like

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 179, 126, 192, 124)
$But1 = GUICtrlCreateButton("Click me", 40, 24, 75, 25)
$But2 = GUICtrlCreateButton("New Button", 40, 64, 75, 25)
GUICtrlSetState($But2, $GUI_HIDE)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $But1
   GUICtrlSetState($But2, $GUI_SHOW)
EndSwitch
WEnd

:)

Edited by mischieftoo
Link to comment
Share on other sites

Hm, yeah, thanks, thats a smart idea.

There's just one nasty disadvantage; I need to enable and disable all controlls at every button. For instance, $but3 should enable $but4, then I should hide all other controls at every other click.

Case $but1
            GUICtrlSetState($but2,64)
            GUICtrlSetState($but3,32)
            GUICtrlSetState($but4,32)

          Case $but2
            GUICtrlSetState($but3,64)
            GUICtrlSetState($but4,32)
            GUICtrlSetState($but1,32)

And so on..

Not really convenient when having over 100 different items, check boxes, buttons etc..

Isn't it possible to for instance group a load of controlls and then show or hide them all at once?

Edited by WJST
Link to comment
Share on other sites

  • Moderators

WJST,

Unfortunately not. You could put the ControlIDs into an array which would let you use a For...Next loop to run through them pretty quickly. :)

But if you are really dealing with over 100 controls, I would seriously reconsider your GUI design. Perhaps take a look at my GUIExtender UDF (look in my sig for the link) - this will let you open and close sections of your GUI and might be a better way to deal with so many controls. :D

M23

P.S. I amended the thread title for you - see the first post for more details. ;)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

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...