Jump to content

Very Simple GUI Button problem


Ivan808
 Share

Recommended Posts

I am sorry and embarrassed that I even have to post this problem of mine. I can't for the life of me, figure out how to open another created form from a button.

Ie:

Mainform

Button1 (should open Form2)

Form2

Button1 (should hide form2 and open form3)

Again i know this is has got to be sooo simple... but I just cant find the information (and believe me, ive looked) to figure this out. I am obviously very new at AutoIt and am really enjoying the possibilities of what I could do with this. I have searched through the Help file and its still mainly foreign to me.

Thanks in advance for the help.

Ivan

Here is what I created so far.

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


Opt("GUIOnEventMode", 1)
;MAIN FORM
#Region ### START Koda GUI section ### Form=MAIN FORM
$Form1 = GUICreate("Form1", 625, 443, 192, 124)
$form1_button1 = GUICtrlCreateButton("Open Form 2", 136, 48, 73, 97, $WS_GROUP)
GUICtrlSetOnEvent(-1, "Button1Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func Button1Click()
    
EndFunc


Opt("GUIOnEventMode", 1)
;FORM2
#Region ### START Koda GUI section ### Form=FORM2
$Form2 = GUICreate("Form2", 625, 443, 192, 124)
$form2_button1 = GUICtrlCreateButton("Open Form 3", 88, 88, 105, 65, $WS_GROUP)
GUICtrlSetOnEvent(-1, "form2_button1Click")
$Label1 = GUICtrlCreateLabel("*Hide Form 2 but open Form 3", 80, 168, 161, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func form2_button1Click()

EndFunc


Opt("GUIOnEventMode", 1)
;FORM3
#Region ### START Koda GUI section ### Form=FORM3
$Form3 = GUICreate("Form3", 625, 443, 192, 124)
$form3_Button1 = GUICtrlCreateButton("Close From 3", 128, 64, 105, 57, $WS_GROUP)
GUICtrlSetOnEvent(-1, "form3_Button1Click")
$Label1 = GUICtrlCreateLabel("*Close From 3 and show form 2 again.", 96, 160, 182, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func form3_Button1Click()

EndFunc
Edited by Ivan808
Link to comment
Share on other sites

http://www.autoitscript.com/forum/index.php?showtopic=105757&view=findpost&p=747307

I believe this above link is my answer... I am researching and playing around with it. Maybe I should have looked a few posts down. Five hours of my life GONE! :)

Link to comment
Share on other sites

hi, I corrected your code. I didn't put guictrlsetonevent in the script because I don't like it :)

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


FORM1()

Func FORM1()
;MAIN FORM
#Region ### START Koda GUI section ### Form=MAIN FORM
$Form1 = GUICreate("Form1", 625, 443, 192, 124)
$form1_button1 = GUICtrlCreateButton("Open Form 2", 136, 48, 73, 97, $WS_GROUP)
;GUICtrlSetOnEvent(-1, "Button1Click")
GUISetState()
#EndRegion ### END Koda GUI section ###

 While 1
        $nMsg = GUIGetMsg()
        Select
            Case $nMsg = $form1_button1
                GUIDelete($Form1)
                FORM2()
            Case $nMsg = -3
                Exit
        EndSelect
        WEnd

EndFunc

;FORM2
Func FORM2()
#Region ### START Koda GUI section ### Form=FORM2
$Form2 = GUICreate("Form2", 500, 343, 192, 124)
$form2_button1 = GUICtrlCreateButton("Open Form 3", 88, 88, 105, 65, $WS_GROUP)
;GUICtrlSetOnEvent(-1, "form2_button1Click")
$Label1 = GUICtrlCreateLabel("*Hide Form 2 but open Form 3", 80, 168, 161, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Select
            Case $nMsg = $form2_button1
                GUIDelete($Form2)
                FORM3()
            Case $nMsg = -3
                Exit
        EndSelect
WEnd

EndFunc

;FORM3
Func FORM3()
#Region ### START Koda GUI section ### Form=FORM3
$Form3 = GUICreate("Form3", 300, 250, 192, 124)
$form3_Button1 = GUICtrlCreateButton("Close From 3", 128, 64, 105, 57, $WS_GROUP)
;GUICtrlSetOnEvent(-1, "form3_Button1Click")
$Label1 = GUICtrlCreateLabel("*Close From 3 and show form 2 again.", 96, 160, 182, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Select
            Case $nMsg = $form3_Button1
                GUIDelete($Form3)
                FORM1()
            Case $nMsg = -3
                Exit
        EndSelect
WEnd

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