Sign in to follow this  
Followers 0
cheeseslice

can I have 2 forms within the same application?

5 posts in this topic

i don't know if this is a stupid question or not but is it possible to have two forms within the one application?

once the first part of my script has finished i want it to disappear and a new form to load with a new set of options and styles.

thanks

CS

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

i don't know if this is a stupid question or not but is it possible to have two forms within the one application?

once the first part of my script has finished i want it to disappear and a new form to load with a new set of options and styles.

thanks

CS

Yes it's possible... to make it easy on yourself, just put them in a function

pseudo:

_Form1()
_Form2()
Exit

Func _Form1()
   gui stuff
   action stuff
   guidelete()
   return
EndFunc

Func _Form2()
   gui stuff
   action stuff
   guidelete()
   return
EndFunc
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.

Share this post


Link to post
Share on other sites

Yes it's possible... to make it easy on yourself, just put them in a function

pseudo:

_Form1()
_Form2()
Exit

Func _Form1()
   gui stuff
   action stuff
   guidelete()
   return
EndFunc

Func _Form2()
   gui stuff
   action stuff
   guidelete()
   return
EndFunc
thanks for the reply, this then brings me to another question. How can I have functions within functions? I have just tried the method you suggested and I am getting a syntax error at the first func within the _form1 function.

Thanks again.

Share this post


Link to post
Share on other sites

thanks for the reply, this then brings me to another question. How can I have functions within functions? I have just tried the method you suggested and I am getting a syntax error at the first func within the _form1 function.

Thanks again.

You do not need functions to run multiple forms.... :)

Heres an example

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form 2", 340, 52, 199, 255)
$Label2 = GUICtrlCreateLabel("The text you entered was:", 4, 6, 127, 17)
$Label3 = GUICtrlCreateLabel("AutoIt Rocks", 6, 22, 303, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form 1", 316, 109, 193, 115)
$Label1 = GUICtrlCreateLabel("Enter some text and click HitMe", 7, 11, 154, 17)
$text = GUICtrlCreateInput("AutoIt Rocks", 8, 27, 121, 21)
$Button1 = GUICtrlCreateButton("Hit Me", 7, 50, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            GuiCtrlSetData($Label3, GuiCtrlRead($text))
    EndSwitch
WEnd

I can do signature me.

Share this post


Link to post
Share on other sites

Or...

#include <GUIConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form 1", 316, 109, 193, 115)
$Label1 = GUICtrlCreateLabel("Enter some text and click HitMe", 7, 11, 154, 17)
$text = GUICtrlCreateInput("AutoIt Rocks", 8, 27, 121, 21)
$Button1 = GUICtrlCreateButton("Hit Me", 7, 50, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form 2", 340, 52, 199, 255,-1,-1,$Form1)
$Label2 = GUICtrlCreateLabel("The text you entered was:", 4, 6, 127, 17)
$Label3 = GUICtrlCreateLabel("AutoIt Rocks", 6, 22, 303, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $nMsg = GUIGetMsg(1)
    Switch $nMsg[0]
        Case $GUI_EVENT_CLOSE
            If $nMsg[1]=$Form1 Then 
                Exit
            Else
                GUIDelete($nMsg[1])
            EndIf
        Case $Button1
            GuiCtrlSetData($Label3, GuiCtrlRead($text))
    EndSwitch
WEnd

This way there's only one button in the taskbar and you can close them individually. Except of course, if you close the main GUI.

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  
Followers 0