Jump to content

How to properly create a Back Next Finish form?


DannyJ
 Share

Go to solution Solved by Luke94,

Recommended Posts

 I have multiple forms, with next and back buttons. (Code below)

My first question would be to this form, how to disable the back button with GUICtrlSetState($Button_2,$GUI_DISABLE), in the first form?

My second question would, be If I am in the last page I need to change the button text to  GUICtrlSetData($Button_1,"FINISH")?

In essence, how to determine which page I am currently standing in my code below?

The last and final question would be that, the program allows the user to click to the Next button if all the inputs are not empty or something written in the input, how to solve this?

Thank you in advance your help :D

 

#include <GuiConstants.au3>

Dim $show = 0, $Child_[4], $children = 3, $Radio[11]

$Main = GUICreate("MyGUI", (@DesktopWidth) / 4, (@DesktopHeight ) / 2, (@DesktopWidth) / 2, (@DesktopHeight ) / 2)

$ButtonPostion_Y = 490

$Button_Width = 80
$Button_Height = 25


$CancelButtonPostion_X = 335
$NextButtonPostion_X = $CancelButtonPostion_X - $Button_Width - 10
$BackButtonPostion_X =  $CancelButtonPostion_X-  $Button_Width - $Button_Width - 10




$Button_1 = GUICtrlCreateButton("&Next >", $NextButtonPostion_X, $ButtonPostion_Y, $Button_Width, $Button_Height)
$Button_2 = GUICtrlCreateButton("< &Back",$BackButtonPostion_X,$ButtonPostion_Y ,$Button_Width, $Button_Height)
$Button_3 = GUICtrlCreateButton("&Cancel", $CancelButtonPostion_X, $ButtonPostion_Y, $Button_Width, $Button_Height)


GUISetState()

$Child_[1] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
$Label_1 = GuiCtrlCreateLabel("Child 1.", 40, 140, 290, 30)
;~ GUICtrlSetState($Button_2,$GUI_DISABLE) Not working properly
GUICtrlSetFont(-1, 10, 650)
$radio[1] = GUICtrlCreateInput ("", 10, 10, 120, 20)
$radio[2] = GUICtrlCreateInput ("", 10, 40, 120, 20)
GUISetState()

$Child_[2] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
$Label_1 = GuiCtrlCreateLabel("Child 2.", 40, 140, 290, 30)
GUICtrlSetState($Button_2,$GUI_ENABLE)
GUICtrlSetFont(-1, 10, 650)
$radio[3] = GUICtrlCreateInput ("", 10, 10, 120, 20)
$radio[4] = GUICtrlCreateInput ("", 10, 40, 120, 20)
GUISetState(@SW_HIDE)

$Child_[3] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
;~  GUICtrlSetData($Button_1,"FINISH") Not working properly
$Label_1 = GuiCtrlCreateLabel("Child 3.", 40, 140, 290, 30)
GUICtrlSetFont(-1, 10, 650)




GUISetState(@SW_HIDE)


While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button_3
            ExitLoop
        Case $msg = $Button_1
            Set_Next()
        Case $msg = $Button_2
            Set_Back()
        ;Case $msg = $Button_4
          ;  Set_Done()
            ;;;
    EndSelect
WEnd


;--------- Functions -------------------

Func Set_Done()
for $x = 1 to UBound($radio) -1
    If _IsChecked($radio[$x]) Then MsgBox(0x0,"#" & $x, "You selected Radio " & $x, 2)
    Next
EndFunc

Func Set_Next()

    For $x = 1 To $children - 1
        $Nwin = WinGetState($Child_[$x])
        If $Nwin > 5 Then
            GUISetState(@SW_HIDE, $Child_[$x])
            GUISetState(@SW_SHOW, $Child_[$x + 1])
            Return
        EndIf
    Next

EndFunc   ;==>Set_Next

Func Set_Back()

    For $x = $children To 1 Step - 1
        $Nwin = WinGetState($Child_[$x])
        If $Nwin > 5 Then
            GUISetState(@SW_HIDE, $Child_[$x])
            GUISetState(@SW_SHOW, $Child_[$x - 1])
            Return
        EndIf
    Next

EndFunc   ;==>Set_Back

Func _IsChecked($control)
    Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

 

Link to comment
Share on other sites

  • Solution

Very messy.. See below:

#include <GuiConstants.au3>

Global $g_iIndex = 1 ; <--- This is the current tab index which will only be changed when we press the Next/Back buttons

Dim $show = 0, $Child_[4], $children = 3, $Radio[11]

$Main = GUICreate("MyGUI", (@DesktopWidth) / 4, (@DesktopHeight ) / 2, (@DesktopWidth) / 2, (@DesktopHeight ) / 2)

$ButtonPostion_Y = 490

$Button_Width = 80
$Button_Height = 25


$CancelButtonPostion_X = 335
$NextButtonPostion_X = $CancelButtonPostion_X - $Button_Width - 10
$BackButtonPostion_X =  $CancelButtonPostion_X-  $Button_Width - $Button_Width - 10




$Button_1 = GUICtrlCreateButton("&Next >", $NextButtonPostion_X, $ButtonPostion_Y, $Button_Width, $Button_Height)
$Button_2 = GUICtrlCreateButton("< &Back",$BackButtonPostion_X,$ButtonPostion_Y ,$Button_Width, $Button_Height)
$Button_3 = GUICtrlCreateButton("&Cancel", $CancelButtonPostion_X, $ButtonPostion_Y, $Button_Width, $Button_Height)
$Label_2 = GuiCtrlCreateLabel("You're are currently viewing Child " & $g_iIndex, 300, 300, 290, 30) ; Added this so you can see what tab you're viewing


GUISetState()

$Child_[1] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
$Label_1 = GuiCtrlCreateLabel("Child 1.", 40, 140, 290, 30)
;~ GUICtrlSetState($Button_2,$GUI_DISABLE) Not working properly <--- You're disabling $Button_2 here, which is working
GUICtrlSetFont(-1, 10, 650)
$radio[1] = GUICtrlCreateInput ("", 10, 10, 120, 20)
$radio[2] = GUICtrlCreateInput ("", 10, 40, 120, 20)
GUISetState()

$Child_[2] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
$Label_1 = GuiCtrlCreateLabel("Child 2.", 40, 140, 290, 30)
;~ GUICtrlSetState($Button_2,$GUI_ENABLE) <--- But you're enabling $Button_2 here, which is why it appears to not be working
GUICtrlSetFont(-1, 10, 650)
$radio[3] = GUICtrlCreateInput ("", 10, 10, 120, 20)
$radio[4] = GUICtrlCreateInput ("", 10, 40, 120, 20)
GUISetState(@SW_HIDE)

$Child_[3] = GUICreate("", 508, 238, 1, 1, BitOR($WS_CHILD, $WS_TABSTOP) + $WS_DLGFRAME, -1, $Main)
;~  GUICtrlSetData($Button_1,"FINISH") Not working properly <-- This should have been setting $Button_1 to "FINISH" on startup?
$Label_1 = GuiCtrlCreateLabel("Child 3.", 40, 140, 290, 30)
GUICtrlSetFont(-1, 10, 650)

GUICtrlSetState($Button_2,$GUI_DISABLE) ; <--- Enable $Button_2 here as we want to disable it on start.


GUISetState(@SW_HIDE)


While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button_3
            ExitLoop
        Case $msg = $Button_1
            Set_Next()
        Case $msg = $Button_2
            Set_Back()
        ;Case $msg = $Button_4
          ;  Set_Done()
            ;;;
    EndSelect
WEnd


;--------- Functions -------------------

Func Set_Done()
for $x = 1 to UBound($radio) -1
    If _IsChecked($radio[$x]) Then MsgBox(0x0,"#" & $x, "You selected Radio " & $x, 2)
    Next
EndFunc

;~ Func Set_Next()

;~     For $x = 1 To $children - 1
;~         $Nwin = WinGetState($Child_[$x])
;~         If $Nwin > 5 Then
;~             GUISetState(@SW_HIDE, $Child_[$x])
;~             GUISetState(@SW_SHOW, $Child_[$x + 1])
;~             Return
;~         EndIf
;~     Next

;~ EndFunc   ;==>Set_Next

Func _CheckInputs()
   Switch $g_iIndex
   Case 1 ; Child 1
      If StringLen(GUICtrlRead($radio[1])) > 0 And _
         StringLen(GUICtrlRead($radio[2])) > 0 Then
         Return True
      EndIf
   Case 2 ; Child 2
      If StringLen(GUICtrlRead($radio[3])) > 0 And _
         StringLen(GUICtrlRead($radio[4])) > 0 Then
         Return True
      EndIf
   Case 3 ; Child 3
      Return True
   EndSwitch
   Return False
EndFunc

Func Set_Next()
   If Not _CheckInputs() Then ; Check to make sure the input boxes aren't empty
      Return
   EndIf
    _HideAll() ; Hide all Children
    $g_iIndex += 1 ; Increase the current tab index
    If $g_iIndex > 1 Then ; If the current tab index is > 1 then Enable the Back button
       GUICtrlSetState($Button_2, $GUI_ENABLE)
   EndIf
    If $g_iIndex >= 3 Then ; Check we're not going passed the amount of tabs we have (3)
       $g_iIndex = 3
       GUICtrlSetData($Button_1,"FINISH") ; If we're at tab 3, or higher, change $Button_1 text to Finish
    Else
       GUICtrlSetData($Button_1,"&Next >") ; Otherwise set the text to Next
    EndIf
    GUICtrlSetData($Label_2, "You're are currently viewing Child " & $g_iIndex) ; Update $Label_2
    GUISetState(@SW_SHOW, $Child_[$g_iIndex]) ; Show the next Child, we've already increased $g_iIndex above
EndFunc

Func _HideAll()
    For $i = 1 To ($children - 1) Step 1
        GUISetState(@SW_HIDE, $Child_[$i])
    Next
EndFunc

;~ Func Set_Back()

;~     For $x = $children To 1 Step - 1
;~         $Nwin = WinGetState($Child_[$x])
;~         If $Nwin > 5 Then
;~             GUISetState(@SW_HIDE, $Child_[$x])
;~             GUISetState(@SW_SHOW, $Child_[$x - 1])
;~             Return
;~         EndIf
;~     Next

;~ EndFunc   ;==>Set_Back

Func Set_Back() ; This is pretty much the same as Set_Next but in reverse
   _HideAll()
   $g_iIndex -= 1
   If $g_iIndex <= 1 Then
      $g_iIndex = 1
      GUICtrlSetState($Button_2, $GUI_DISABLE)
   Else
      GUICtrlSetState($Button_2, $GUI_ENABLE)
   EndIf
   If $g_iIndex < 3 Then
      GUICtrlSetData($Button_1,"&Next >")
   EndIf
   GUICtrlSetData($Label_2, "You're are currently viewing Child " & $g_iIndex)
    GUISetState(@SW_SHOW, $Child_[$g_iIndex])
EndFunc

Func _IsChecked($control)
    Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

I've left comments in response to your questions. ☺️

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