Jump to content
Sign in to follow this  
toonboon

GUI listbox add from new form. HELP?

Recommended Posts

toonboon

I have this form which has a ListBox and a button. The button reads "add" when I click on the button, it needs to open another form of GUI which has one text input and a button that reads "add". When I enter text in the input, and click the button the text I entered is added to the ListBox. when I close the freshly opened GUI it should do nothing.

The problem I have here is that it doesn't even close the freshly opened GUI anymore. I have to kill the process through the tray icon to be able to do anything else =/

help please :P


[right]~What can I say, I'm a Simplistic person[/right]

Share this post


Link to post
Share on other sites
Andreik

I have this form which has a ListBox and a button. The button reads "add" when I click on the button, it needs to open another form of GUI which has one text input and a button that reads "add". When I enter text in the input, and click the button the text I entered is added to the ListBox. when I close the freshly opened GUI it should do nothing.

The problem I have here is that it doesn't even close the freshly opened GUI anymore. I have to kill the process through the tray icon to be able to do anything else =/

help please :P

Please post your code or a part of code to can help you.


When the words fail... music speaks

Share this post


Link to post
Share on other sites
toonboon

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

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("ListBoxTest", 289, 303, 194, 125)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
$ListBox = GUICtrlCreateList("", 40, 24, 209, 227)
GUICtrlSetOnEvent($ListBox, "ListBoxClick")
$Button1 = GUICtrlCreateButton("Add", 40, 256, 209, 25, 0)
GUICtrlSetOnEvent($Button1, "Button1Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func Button1Click()
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$AddForm = GUICreate("Add...", 233, 93, 232, 129)
$Input = GUICtrlCreateInput("", 24, 16, 177, 21)
$Add = GUICtrlCreateButton("Add", 24, 48, 177, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

EndFunc
Func Form1Close()

EndFunc
Func Form1Maximize()

EndFunc
Func Form1Minimize()

EndFunc
Func Form1Restore()

EndFunc
Func ListBoxClick()

EndFunc

this is my code. I already have some functions added but this way it's kept clean and easy to undertstand :P


[right]~What can I say, I'm a Simplistic person[/right]

Share this post


Link to post
Share on other sites
Zedna

You mixed up OnEvent mode and message loop + you did a lot of another mistakes :-)

Here is corrected/working code:

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

Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("ListBoxTest", 289, 303, 194, 125)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close",$Form1)
$ListBox = GUICtrlCreateList("", 40, 24, 209, 227)
GUICtrlSetOnEvent($ListBox, "ListBoxClick")
$Button1 = GUICtrlCreateButton("Add", 40, 256, 209, 25, 0)
GUICtrlSetOnEvent($Button1, "Button1Click")
GUISetState(@SW_SHOW,$Form1)
#EndRegion ### END Koda GUI section ###

#Region ### START Koda GUI section ### Form=
$AddForm = GUICreate("Add...", 233, 93, 232, 129)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form2Close",$AddForm)
$Input = GUICtrlCreateInput("", 24, 16, 177, 21)
$Add = GUICtrlCreateButton("Add", 24, 48, 177, 25, 0)
GUICtrlSetOnEvent($Add, "Button2Click")
;~ GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func Button1Click()
 GUISetState(@SW_SHOW, $AddForm )
EndFunc

Func Button2Click()
 $value = GUICtrlRead($Input)
 GUICtrlSetData($ListBox, $value)
EndFunc

Func Form1Close()
 Exit
EndFunc

Func Form2Close()
 GUISetState(@SW_HIDE, $AddForm )
EndFunc

Func ListBoxClick()
EndFunc

Share this post


Link to post
Share on other sites
Andreik

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

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("ListBoxTest", 289, 303, 194, 125)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
$ListBox = GUICtrlCreateList("", 40, 24, 209, 227)
GUICtrlSetOnEvent($ListBox, "ListBoxClick")
$Button1 = GUICtrlCreateButton("Add", 40, 256, 209, 25, 0)
GUICtrlSetOnEvent($Button1, "Button1Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func Button1Click()
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$AddForm = GUICreate("Add...", 233, 93, 232, 129)
$Input = GUICtrlCreateInput("", 24, 16, 177, 21)
$Add = GUICtrlCreateButton("Add", 24, 48, 177, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

EndFunc
Func Form1Close()

EndFunc
Func Form1Maximize()

EndFunc
Func Form1Minimize()

EndFunc
Func Form1Restore()

EndFunc
Func ListBoxClick()

EndFunc

this is my code. I already have some functions added but this way it's kept clean and easy to undertstand :P

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("ListBoxTest", 289, 303, 194, 125)
$ListBox = GUICtrlCreateList("", 40, 24, 209, 227)
$Button1 = GUICtrlCreateButton("Add", 40, 256, 209, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $MSG = GUIGetMsg()
    If $MSG = $Button1 Then
        $AddForm = GUICreate("Add...", 233, 93, 232, 129)
        $Input = GUICtrlCreateInput("", 24, 16, 177, 21)
        $Add = GUICtrlCreateButton("Add", 24, 48, 177, 25, 0)
        GUISetState(@SW_SHOW,$AddForm)
        While 1
            $nMSG = GUIGetMsg()
            Switch $nMSG
                Case $Add
                    $TEMP = GUICtrlRead($ListBox)
                    GUICtrlSetData($ListBox,$TEMP & GUICtrlRead($Input) & "|")
                    GUIDelete($AddForm)
                    ExitLoop
                Case -3
                    GUIDelete($AddForm)
                    ExitLoop
            EndSwitch
            Sleep(20)
        WEnd
    ElseIf $MSG = -3 Then
        Exit
    EndIf
    Sleep(20)
WEnd

A simplified version.


When the words fail... music speaks

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.