CodyBarrett

GUI Button event

18 posts in this topic

yeah... VERY simple question eh? well i dont understand how to make a save button save whats in a inputbox into a .ini file... i cant even make it so when u hit SAVE a msg box pops up... can you guys teach me how to make a GUI button event? it would be very helpfull :mellow: (help file doesnt help\i have searched the forums)

thank you guys

Share this post


Link to post
Share on other sites



Here is my code for my GUI.... i need help with the buttons and the saving and loading .ini, but once i learn how to do the button i should figure out the rest eventually

; This script shows manual positioning of all controls;
;   there are much better methods of positioning...
#include <GuiConstantsEx.au3>
#include <AVIConstants.au3>
#include <TreeViewConstants.au3>
#include <ButtonConstants.au3>
Global $personalinput = GuiCtrlCreateInput(" ", 0, 130, 400, 200)
Global $addmembers
Global $deletemembers
Global $memberinput

DirCreate("C:\GUILDINFO")
If FileExists("C:\guildinfo\C members.ini") Then
    MsgBox(0, "Current Members.ini", "DOES Exist")
Else
    MsgBox(64,"no", "Does NOT exists")
    IniWrite("C:\guildinfo\C members.ini", "CURRENT", "key", "*")
    MsgBox(64,"NOW", "it exists")
EndIf
If FileExists("C:\guildinfo\Deserters.ini") Then
    MsgBox(0, "Deserters.ini", "DOES Exist")
Else
    MsgBox(64,"no", "Does NOT exists")
    IniWrite("C:\guildinfo\Deserters.ini", "DESERTERS", "key", "*")
    MsgBox(64,"NOW", "it exists")
EndIf
If FileExists("C:\guildinfo\Personal.ini") Then
    MsgBox(0, "Personal.ini", "DOES Exist")
Else
    MsgBox(64,"no", "Does NOT exists")
    IniWrite("C:\guildinfo\Personal.ini", "Personal", "key", "*")
    MsgBox(64,"NOW", "it exists")
EndIf

; GUI
GuiCreate("GUILD INFORMATION", 400, 400)
GuiSetIcon(@SystemDir & "\mspaint.exe", 0)

; PIC
GuiCtrlCreatePic("guild.bmp",0,0, 399,79)

; TAB
GuiCtrlCreateTab(0, 80)
GuiCtrlCreateTabItem("Personal")

; INPUT
GuiCtrlCreateInput(" ", 0, 130, 400, 200)

; BUTTON
GuiCtrlCreateButton("SAVE", 0, 350, 100, 30)

Func save()
    
Local $SAVE = GuiCtrlCreateButton("SAVE", 0, 350, 100, 30)
GUICtrlSetOnEvent(1, "SAVEPressed")

GUISetState(@SW_SHOW)

; Just idle around
While 1
    Sleep(10)
WEnd

EndFunc  ;==>Example
Func SAVEPressed()
    MsgBox(0, "SAVED")
EndFunc  ;==>SAVEPressed



; TAB
GuiCtrlCreateTab(0, 80)
GuiCtrlCreateTabItem("Guild")

; LABLE
GUICtrlCreateLabel("GUILD LISTINGS", 10, 110, 150, 50)

; INPUT
GuiCtrlCreateInput("Add\Delete Member", 0, 110, 224, 20)

; BUTTON
GuiCtrlCreateButton("Add ", 226, 110, 80, 20)

; BUTTON
GuiCtrlCreateButton("Delete", 306,  110, 80, 20)

; LIST VIEW
$listView = GuiCtrlCreateListView("Member|Rank|Warnings|Test Taken|Gone", 0, 160, 399, 80)
GuiCtrlCreateListViewItem("Bobc|1|0|0|0", $listView)
GuiCtrlCreateListViewItem("Aniry|1|0|0|0", $listView)

; DATE
GuiCtrlCreateDate("", 0, 380, 200, 20)

; GUI MESSAGE LOOP
GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd

please and thank you... (button presses but nothing else happens)

Share this post


Link to post
Share on other sites

You have two While loops. One will never end. You need only to have one.

$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button1
;code here
EndSwitch
WEnd

Share this post


Link to post
Share on other sites

You have two While loops. One will never end. You need only to have one.

$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button1
;code here
EndSwitch
WEnd
uhhmmm please excuse me for asking... where do i put the lil bit of script u gave me... and i DO see where i dont need another WHILE thanks for pointing that out

Share this post


Link to post
Share on other sites

Try to keep all GUI stuff together,then your loop, then functions. It's easier to read.

include <GuiConstantsEx.au3>
#include <AVIConstants.au3>
#include <TreeViewConstants.au3>
#include <ButtonConstants.au3>
Global $personalinput = GuiCtrlCreateInput(" ", 0, 130, 400, 200)
Global $addmembers
Global $deletemembers
Global $memberinput

DirCreate("C:\GUILDINFO")
If FileExists("C:\guildinfo\C members.ini") Then
    MsgBox(0, "Current Members.ini", "DOES Exist")
Else
    MsgBox(64,"no", "Does NOT exists")
    IniWrite("C:\guildinfo\C members.ini", "CURRENT", "key", "*")
    MsgBox(64,"NOW", "it exists")
EndIf
If FileExists("C:\guildinfo\Deserters.ini") Then
    MsgBox(0, "Deserters.ini", "DOES Exist")
Else
    MsgBox(64,"no", "Does NOT exists")
    IniWrite("C:\guildinfo\Deserters.ini", "DESERTERS", "key", "*")
    MsgBox(64,"NOW", "it exists")
EndIf
If FileExists("C:\guildinfo\Personal.ini") Then
    MsgBox(0, "Personal.ini", "DOES Exist")
Else
    MsgBox(64,"no", "Does NOT exists")
    IniWrite("C:\guildinfo\Personal.ini", "Personal", "key", "*")
    MsgBox(64,"NOW", "it exists")
EndIf

; GUI
GuiCreate("GUILD INFORMATION", 400, 400)
GuiSetIcon(@SystemDir & "\mspaint.exe", 0)

; PIC
GuiCtrlCreatePic("guild.bmp",0,0, 399,79)

; TAB
GuiCtrlCreateTab(0, 80)
GuiCtrlCreateTabItem("Personal")

; INPUT
GuiCtrlCreateInput(" ", 0, 130, 400, 200)

; BUTTON
GuiCtrlCreateButton("SAVE", 0, 350, 100, 30)


; TAB
GuiCtrlCreateTab(0, 80)
GuiCtrlCreateTabItem("Guild")

; LABLE
GUICtrlCreateLabel("GUILD LISTINGS", 10, 110, 150, 50)

; INPUT
GuiCtrlCreateInput("Add\Delete Member", 0, 110, 224, 20)

; BUTTON
GuiCtrlCreateButton("Add ", 226, 110, 80, 20)

; BUTTON
GuiCtrlCreateButton("Delete", 306,   110, 80, 20)

; LIST VIEW
$listView = GuiCtrlCreateListView("Member|Rank|Warnings|Test Taken|Gone", 0, 160, 399, 80)
GuiCtrlCreateListViewItem("Bobc|1|0|0|0", $listView)
GuiCtrlCreateListViewItem("Aniry|1|0|0|0", $listView)

; DATE
GuiCtrlCreateDate("", 0, 380, 200, 20)

; GUI MESSAGE LOOP
GuiSetS
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button1
;code here
EndSwitch
WEnd

Func save()
    
Local $SAVE = GuiCtrlCreateButton("SAVE", 0, 350, 100, 30)
GUICtrlSetOnEvent(1, "SAVEPressed")

GUISetState(@SW_SHOW)

EndFunc ;==>Example
Func SAVEPressed()
    MsgBox(0, "SAVED")
EndFunc ;==>SAVEPressed

Cleaned slightly.

Share this post


Link to post
Share on other sites

thanks i appreciate it :mellow:.... EDIT

i seem to have a problem... first i got * undeclared variable* so i fixed that... then the whole GUI didnt even show up im gonna play with it for a while

Share this post


Link to post
Share on other sites

i have KODA but i cannot make a button event on it either xD... i did this code bye copying the example GUI and remaking it ( 'cause i just learned how to do GUI like 2 days ago but still haveing trouble).. i did it by hand.... most of it

Share this post


Link to post
Share on other sites

For Koda just double click your button and set the event to notify. If you want to do the even by hand just do

Case $button_name
;code for event

Share this post


Link to post
Share on other sites

hmmm i still dont get KODA.... (thickskull eh?) illl stick to SCITE for right now

Share this post


Link to post
Share on other sites

Koda is really simple. Open Koda, design your GUI, save if you intend to edit later, press F9, click "Insert into SciTE",and your GUI code will be added at the cursor position.

Share this post


Link to post
Share on other sites

Koda is really simple. Open Koda, design your GUI, save if you intend to edit later, press F9, click "Insert into SciTE",and your GUI code will be added at the cursor position.

well.... ok... ill try that later, but i still cant make the buttons have the event i want. i even copeid from some other examples and edited it so it should work.... oh gawd. how do i tell it---- "when button is clicked, do this"---- everytime i try it always seems to do the action BEFORE i click it, like it starts up that way. help? please lol before i start whining xD, ok i got myself under control. anyway any ideas?

Share this post


Link to post
Share on other sites

I already told you how. Put the Case statements in your While 1 loop, put the code on the line below, then you have a working event. See demo below.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 256, 124, 193, 115)
$Input1 = GUICtrlCreateInput("Input1", 16, 24, 121, 21)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 48, 80, 97, 17)
$Button1 = GUICtrlCreateButton("Button1", 152, 32, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            MsgBox(0,"Button 1","Button 1 was clicked")
        Case $Checkbox1
            MsgBox(0,"Checkbox 1","Checkbox 1 is " & GUICtrlRead($Checkbox1))
        Case $Input1
            MsgBox(0,"Input 1","You typed: " & GUICtrlRead($Input1))
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

wow... well thanks i got it now :mellow: i dont see how i missed it before... thankyou for your pasience

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

well now.. i got that... (technically this is still in this topic) how would i go about saveing an edit box into an .ini file once the SAVE button is pressed i tryed INIWRITE("guild.ini", $editbox) but whenever i do that and i open the ini i always see a numeric value like (6) or (7) any hints?

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