Jump to content
Sign in to follow this  
Mannyfresh31

How to add controls to an existing running GUI?

Recommended Posts

Mannyfresh31

ok guys I'm trying to do an alarm app but I just can get it to work because I need to add new tabs with controls for each alarm can you please help me get it done?

This is what I got so far

#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <Misc.au3>
#include <ColorConstants.au3>
#include <TabConstants.au3>
#include <GuiTab.au3>


;No Tray Icon
;Opt("TrayIconHide", 1)
AutoItSetOption("GUICloseOnESC",0 )
;Opt("TrayAutoPause",0)
Opt("TrayMenuMode",1)


;One Instace Only
_Singleton("NGT Alarm por Manuel Hernández", 0)

$SettingsFile = @ScriptDir & "\AlarmSettings.ini"
if FileExists ($SettingsFile) = 0 Then
FileWrite($SettingsFile,";NGT Alarm Settings"&@CRLF&@CRLF&@CRLF&@CRLF&@CRLF)
IniWriteSection(@ScriptDir & "\AlarmSettings.ini","Alarms","Count=1")
Global $Count =1
Else
    $Count = IniRead($SettingsFile,"Alarms","Count","")
EndIf


Global $TabSheet[$Count], $Add[$Count],$Remove[$Count],$Date[$Count],$Checkbox8[$Count],$Label1[$Count],$Checkbox1[$Count]
Global $Checkbox2[$Count],$Checkbox3[$Count],$Checkbox4[$Count],$Checkbox5[$Count],$Checkbox6[$Count],$Checkbox7[$Count],$Label2[$Count]
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("NGT Alarm por Manuel Hernández", 560, 216, 192, 124)
Global $Tab1 = GUICtrlCreateTab(0, 0, 560, 216)

For $i = 0  to $Count -1
 $TabSheet[$i] = GUICtrlCreateTabItem("Alarma " & $i+1)
;Global $TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
 $Add[$i] = GUICtrlCreateButton("+",15,30,40,20)
 $Remove[$i] = GUICtrlCreateButton("-",15,50,40,20)
$Date[$i] = GUICtrlCreateDate("", 240, 20, 90, 25,$DTS_TIMEFORMAT)
$Checkbox8[$i] = GUICtrlCreateCheckbox("Encendido", 360, 30, 80, 17)
$Label1[$i] = GUICtrlCreateLabel("Repetir", 240, 60, 100, 30)
GUICtrlSetFont(-1, 20, $FW_BOLD,$GUI_FONTNORMAL,"Arial") ; Set the font of the previous control.
$Checkbox1[$i] = GUICtrlCreateCheckbox("Lunes", 70, 90, 50, 17)
$Checkbox2[$i] = GUICtrlCreateCheckbox("Martes", 130, 90, 50, 17)
$Checkbox3[$i] = GUICtrlCreateCheckbox("Miercoles",190, 90, 60, 17)
$Checkbox4[$i] = GUICtrlCreateCheckbox("Jueves", 260, 90, 50, 17)
$Checkbox5[$i] = GUICtrlCreateCheckbox("Viernes", 320, 90, 60, 17)
$Checkbox6[$i] = GUICtrlCreateCheckbox("Sabado", 380, 90, 55, 17)
$Checkbox7[$i] = GUICtrlCreateCheckbox("Domingo", 440, 90, 60, 17)
$Label2[$i] = GUICtrlCreateLabel("Alarma Desactivada", 100, 150, 400, 50)
GUICtrlSetFont(-1, 30, $FW_BOLD,$GUI_FONTNORMAL,"Impact") ; Set the font of the previous control.
GUICtrlSetColor(-1, $COLOR_RED); Set the color of the label control.
Next




Global $iSettings = TrayCreateMenu("Click Aqui!") ; Create a tray menu sub menu with two sub items.
Global $Monstar = TrayCreateItem("Mostar", $iSettings)
Global $Esconder = TrayCreateItem("Esconder", $iSettings)
TrayCreateItem("") ; Create a separator line.


GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Func Adding()
    GUIDelete()
For $i = $Count -1 to $Count
 $TabSheet[$i] = GUICtrlCreateTabItem("Alarma " & $i + 1)
;Global $TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
 $Add[$i] = GUICtrlCreateButton("+",15,30,40,20)
 $Remove[$i] = GUICtrlCreateButton("-",15,50,40,20)
$Date[$i] = GUICtrlCreateDate("", 240, 20, 90, 25,$DTS_TIMEFORMAT)
$Checkbox8[$i] = GUICtrlCreateCheckbox("Encendido", 360, 30, 80, 17)
$Label1[$i] = GUICtrlCreateLabel("Repetir", 240, 60, 100, 30)
GUICtrlSetFont(-1, 20, $FW_BOLD,$GUI_FONTNORMAL,"Arial") ; Set the font of the previous control.
$Checkbox1[$i] = GUICtrlCreateCheckbox("Lunes", 70, 90, 50, 17)
$Checkbox2[$i] = GUICtrlCreateCheckbox("Martes", 130, 90, 50, 17)
$Checkbox3[$i] = GUICtrlCreateCheckbox("Miercoles",190, 90, 60, 17)
$Checkbox4[$i] = GUICtrlCreateCheckbox("Jueves", 260, 90, 50, 17)
$Checkbox5[$i] = GUICtrlCreateCheckbox("Viernes", 320, 90, 60, 17)
$Checkbox6[$i] = GUICtrlCreateCheckbox("Sabado", 380, 90, 55, 17)
$Checkbox7[$i] = GUICtrlCreateCheckbox("Domingo", 440, 90, 60, 17)
$Label2[$i] = GUICtrlCreateLabel("Alarma Desactivada", 100, 150, 400, 50)
GUICtrlSetFont(-1, 30, $FW_BOLD,$GUI_FONTNORMAL,"Impact") ; Set the font of the previous control.
GUICtrlSetColor(-1, $COLOR_RED); Set the color of the label control.
;$1 += 1
Next

GUISetState(@SW_SHOW)
EndFunc

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Add[0] to $Add[$Count-1]
            $Count+=1
            Adding ()

            IniWrite($SettingsFile,"Alarms","Count",$Count)



    EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites
AutoBert

Try this one

#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <Misc.au3>
#include <ColorConstants.au3>
#include <TabConstants.au3>
#include <GuiTab.au3>


;No Tray Icon
;Opt("TrayIconHide", 1)
AutoItSetOption("GUICloseOnESC", 0)
;Opt("TrayAutoPause",0)
Opt("TrayMenuMode", 1)


;One Instace Only
_Singleton("NGT Alarm por Manuel Hernández", 0)

$SettingsFile = @ScriptDir & "\AlarmSettings.ini"
If FileExists($SettingsFile) = 0 Then
    FileWrite($SettingsFile, ";NGT Alarm Settings" & @CRLF & @CRLF & @CRLF & @CRLF & @CRLF)
    IniWriteSection(@ScriptDir & "\AlarmSettings.ini", "Alarms", "Count=1")
    Global $Count = 1
Else
    $Count = IniRead($SettingsFile, "Alarms", "Count", "")
EndIf

Global $TabSheet[$Count], $Add[$Count], $Remove[$Count], $Date[$Count], $Checkbox8[$Count], $Label1[$Count], $Checkbox1[$Count]
Global $Checkbox2[$Count], $Checkbox3[$Count], $Checkbox4[$Count], $Checkbox5[$Count], $Checkbox6[$Count], $Checkbox7[$Count], $Label2[$Count]
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("NGT Alarm por Manuel Hernández", 560, 216, 192, 124)
Global $Tab1 = GUICtrlCreateTab(0, 0, 560, 216)

For $i = 0 To $Count - 1
    $TabSheet[$i] = GUICtrlCreateTabItem("Alarma " & $i + 1)
    ;Global $TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
    $Add[$i] = GUICtrlCreateButton("+", 15, 30, 40, 20)
    $Remove[$i] = GUICtrlCreateButton("-", 15, 50, 40, 20)
    $Date[$i] = GUICtrlCreateDate("", 240, 20, 90, 25, $DTS_TIMEFORMAT)
    $Checkbox8[$i] = GUICtrlCreateCheckbox("Encendido", 360, 30, 80, 17)
    $Label1[$i] = GUICtrlCreateLabel("Repetir", 240, 60, 100, 30)
    GUICtrlSetFont(-1, 20, $FW_BOLD, $GUI_FONTNORMAL, "Arial") ; Set the font of the previous control.
    $Checkbox1[$i] = GUICtrlCreateCheckbox("Lunes", 70, 90, 50, 17)
    $Checkbox2[$i] = GUICtrlCreateCheckbox("Martes", 130, 90, 50, 17)
    $Checkbox3[$i] = GUICtrlCreateCheckbox("Miercoles", 190, 90, 60, 17)
    $Checkbox4[$i] = GUICtrlCreateCheckbox("Jueves", 260, 90, 50, 17)
    $Checkbox5[$i] = GUICtrlCreateCheckbox("Viernes", 320, 90, 60, 17)
    $Checkbox6[$i] = GUICtrlCreateCheckbox("Sabado", 380, 90, 55, 17)
    $Checkbox7[$i] = GUICtrlCreateCheckbox("Domingo", 440, 90, 60, 17)
    $Label2[$i] = GUICtrlCreateLabel("Alarma Desactivada", 100, 150, 400, 50)
    GUICtrlSetFont(-1, 30, $FW_BOLD, $GUI_FONTNORMAL, "Impact") ; Set the font of the previous control.
    GUICtrlSetColor(-1, $COLOR_RED); Set the color of the label control.
Next





Global $iSettings = TrayCreateMenu("Click Aqui!") ; Create a tray menu sub menu with two sub items.
Global $Monstar = TrayCreateItem("Mostar", $iSettings)
Global $Esconder = TrayCreateItem("Esconder", $iSettings)
TrayCreateItem("") ; Create a separator line.


GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Func Adding()
    ;GUIDelete()
    ConsoleWrite($count&@CRLF)
    ReDim $TabSheet[$Count]          ;-------------
    ReDim $Add[$Count]
    ReDim $Remove[$Count]
    ReDim $Date[$Count]
    ReDim $Label1[$Count]
    ReDim $Label2[$Count]
    ReDim $Checkbox1[$Count]
    ReDim $Checkbox2[$Count]
    ReDim $Checkbox3[$Count]
    ReDim $Checkbox4[$Count]
    ReDim $Checkbox5[$Count]
    ReDim $Checkbox6[$Count]
    ReDim $Checkbox7[$Count]
    ReDim $Checkbox8[$Count]
        $TabSheet[$count-1] = GUICtrlCreateTabItem("Alarma " & $Count)
        ;Global $TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
        $Add[$count-1] = GUICtrlCreateButton("+", 15, 30, 40, 20)
        $Remove[$count-1] = GUICtrlCreateButton("-", 15, 50, 40, 20)
        $Date[$count-1] = GUICtrlCreateDate("", 240, 20, 90, 25, $DTS_TIMEFORMAT)
        $Checkbox8[$count-1] = GUICtrlCreateCheckbox("Encendido", 360, 30, 80, 17)
        $Label1[$count-1] = GUICtrlCreateLabel("Repetir", 240, 60, 100, 30)
        GUICtrlSetFont(-1, 20, $FW_BOLD, $GUI_FONTNORMAL, "Arial") ; Set the font of the previous control.
        $Checkbox1[$count-1] = GUICtrlCreateCheckbox("Lunes", 70, 90, 50, 17)
        $Checkbox2[$count-1] = GUICtrlCreateCheckbox("Martes", 130, 90, 50, 17)
        $Checkbox3[$count-1] = GUICtrlCreateCheckbox("Miercoles", 190, 90, 60, 17)
        $Checkbox4[$count-1] = GUICtrlCreateCheckbox("Jueves", 260, 90, 50, 17)
        $Checkbox5[$count-1] = GUICtrlCreateCheckbox("Viernes", 320, 90, 60, 17)
        $Checkbox6[$count-1] = GUICtrlCreateCheckbox("Sabado", 380, 90, 55, 17)
        $Checkbox7[$count-1] = GUICtrlCreateCheckbox("Domingo", 440, 90, 60, 17)
        $Label2[$count-1] = GUICtrlCreateLabel("Alarma Desactivada", 100, 150, 400, 50)
        GUICtrlSetFont(-1, 30, $FW_BOLD, $GUI_FONTNORMAL, "Impact") ; Set the font of the previous control.
        GUICtrlSetColor(-1, $COLOR_RED); Set the color of the label control.
        GUICtrlCreateTabItem(""); end tabitem definition
    GUISetState(@SW_SHOW)
EndFunc   ;==>Adding

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Add[0] To $Add[$Count - 1]
            $Count += 1
            Adding()

            IniWrite($SettingsFile, "Alarms", "Count", $Count)

    EndSwitch
WEnd

and read about ReDim in the helpfile

Share this post


Link to post
Share on other sites
Mannyfresh31

@AutoBert You're just a Genius my broda thx

 

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  

×