Alle Checkboxen "ankreuzen" Topic is solved

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

User avatar
LuckyJoe
Posts: 341
Joined: 02 Oct 2013, 09:52

Alle Checkboxen "ankreuzen"

03 Jan 2021, 07:15

Hallo zusammen,

ich möchte die Programme auswählen, die beim Hochfahren des PC geladen werden sollen. Dazu habe ich das nachfolgende Gerüst erstellt.

Code: Select all

#NoEnv
#SingleInstance force

Gui, Color, F0F8FF														; Hintergrundfarbe
Gui, Font, cA00000 bold s10, Calibri

Gui, Add, GroupBox, x12  y10 w360 h126             , Startprogramme
Gui, Font, normal cBlack
Gui, Add, CheckBox,  x26  y32 w330 h18 gCheck vCB01 Checked, Programm 01
Gui, Add, CheckBox,  x26  y52 w330 h18 gCheck vCB02 Checked, Programm 02
Gui, Add, CheckBox,  x26  y72 w330 h18 gCheck vCB03 Checked, Programm 03
Gui, Add, CheckBox,  x26  y92 w330 h18 gCheck vCB04 Checked, Programm 04
Gui, Add, CheckBox,  x26 y112 w330 h18 gCheck vCB05 Checked, Programm 05

Gui, Add, Button,     xm y150 w80        , Alle
Gui, Add, Button,   x110 y150 w80 Default, OK

Gui, Show, x1100 y110 Autosize, Startprogramme auswählen
WinSet, AlwaysOnTop, on		  , Startprogramme auswählen
Return

Check:
	GuiControlGet, CBID, Focus          								; IDs control clicked
	GuiControlGet, Status,, %CBID%										; Erkenne Status
	CheckBoxColor(Status, CBID)       									; Setze neuen Font
Return

ButtonAlle:
	Loop, 5
		Control, check,, CB0%A_Index%
Return

ButtonOK:
	Gui, Submit															; Speichert die Inhalte der Steuerelemente in ihre zugeordneten Variablen.
	If CB01
		MsgBox, Programm 01 starten
	If CB02
		MsgBox, Programm 02 starten
	If CB03
		MsgBox, Programm 03 starten
	If CB04
		MsgBox, Programm 04 starten
	If CB05
		MsgBox, Programm 05 starten
	Goto GuiClose
Return

CheckBoxColor(State, ChkBox)
{
	Gui, Font, % State = 0 ? "c7F7F7F Norm"								; Checkbox nicht angehakt
			   : State = 1 ? "cBlack Norm"								; Checkbox angehakt
			   :			 "cDefault"
	GuiControl, Font, %ChkBox%
}

GuiEscape:
GuiClose:
Gui, Destroy
ExitApp
Nun möchte ich mit einem Button "Alle" alle Checkboxen auf einmal "ankreuzen/anhaken", was mir aber nicht gelingt. Was mache ich falsch?

Zusatzfrage:
Wenn alle Checkboxen "angekreuzt/angehakt" sind, soll der Button "Alle" die Beschriftung "Keine" bekommen und mit Klick darauf sollen dementsprechend alle Checkboxen ausgeschaltet (unchecked) werden. Wie funktioniert das?

Danke im Voraus.
Herzliche Grüße aus dem Rheinland
Lucky Joe
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Alle Checkboxen "ankreuzen"

03 Jan 2021, 09:10

Moin,

probier mal:

Code: Select all

#NoEnv
#SingleInstance force

Gui, Color, F0F8FF														; Hintergrundfarbe
Gui, Font, cA00000 bold s10, Calibri

Gui, Add, GroupBox, x12  y10 w360 h126             , Startprogramme
Gui, Font, normal cBlack
Gui, Add, CheckBox,  x26  y32 w330 h18 gCheck vCB01, Programm 01
Gui, Add, CheckBox,  x26  y52 w330 h18 gCheck vCB02, Programm 02
Gui, Add, CheckBox,  x26  y72 w330 h18 gCheck vCB03, Programm 03
Gui, Add, CheckBox,  x26  y92 w330 h18 gCheck vCB04, Programm 04
Gui, Add, CheckBox,  x26 y112 w330 h18 gCheck vCB05, Programm 05
NumCB := 5   ; <<<<<<<<<<
 
Gui, Add, Button,     xm y150 w80      gCheckUncheck       , Alle   ; <<<<<<<<<<
Gui, Add, Button,   x110 y150 w80 Default, OK

Gui, Show, x1100 y110 Autosize, Startprogramme auswählen
WinSet, AlwaysOnTop, on		  , Startprogramme auswählen
Return

Check:
	GuiControlGet, CBID, Focus          								; IDs control clicked
	GuiControlGet, Status,, %CBID%										; Erkenne Status
	CheckBoxColor(Status, CBID)       									; Setze neuen Font
Return

CheckUncheck:
   GuiControlGet, Action, , %A_GuiControl%   ; liest die Beschriftung des Buttons
   If (Action = "Alle") {
      GuiControl, , %A_GuiControl%, Keine    ; ändert die Beschriftung des Buttons
      Check := 1                             ; alle 'checken'
   }
   Else {
      GuiControl, , %A_GuiControl%, Alle
      Check := 0                             ; alle 'unchecken'
   }
   Loop, %NumCB%
      GuiControl, , % Format("CB{:02}", A_Index), %Check%
Return

ButtonOK:
	Gui, Submit															; Speichert die Inhalte der Steuerelemente in ihre zugeordneten Variablen.
	If CB01
		MsgBox, Programm 01 starten
	If CB02
		MsgBox, Programm 02 starten
	If CB03
		MsgBox, Programm 03 starten
	If CB04
		MsgBox, Programm 04 starten
	If CB05
		MsgBox, Programm 05 starten
	Goto GuiClose
Return

CheckBoxColor(State, ChkBox)
{
	Gui, Font, % State = 0 ? "c7F7F7F Norm"								; Checkbox nicht angehakt
			   : State = 1 ? "cBlack Norm"								; Checkbox angehakt
			   :			 "cDefault"
	GuiControl, Font, %ChkBox%
}

GuiEscape:
GuiClose:
Gui, Destroy
ExitApp
User avatar
LuckyJoe
Posts: 341
Joined: 02 Oct 2013, 09:52

Re: Alle Checkboxen "ankreuzen"

03 Jan 2021, 09:24

Hallo just me,

super, funktioniert wie gewünscht! - Danke.
Eine Kleinigkeit, an der mein Herz nicht hängt, wenn es kompliziert wird:
Was muss ich ändern, damit bei "Alle" bzw. "Keine" auch alle Fonts der Checkboxen so geändert werden, wie wenn sie manuell an-/ausgeschaltet werden?
Herzliche Grüße aus dem Rheinland
Lucky Joe
KHA
Posts: 403
Joined: 21 Aug 2018, 11:11

Re: Alle Checkboxen "ankreuzen"  Topic is solved

03 Jan 2021, 10:07

Meinst du vlt. so:

Code: Select all

#NoEnv
#SingleInstance force

Gui, Color, F0F8FF														; Hintergrundfarbe
Gui, Font, cA00000 bold s10, Calibri

Gui, Add, GroupBox, x12  y10 w360 h126             , Startprogramme
Gui, Font, normal cBlack
Gui, Add, CheckBox,  x26  y32 w330 h18 gCheck vCB01, Programm 01
Gui, Add, CheckBox,  x26  y52 w330 h18 gCheck vCB02, Programm 02
Gui, Add, CheckBox,  x26  y72 w330 h18 gCheck vCB03, Programm 03
Gui, Add, CheckBox,  x26  y92 w330 h18 gCheck vCB04, Programm 04
Gui, Add, CheckBox,  x26 y112 w330 h18 gCheck vCB05 checked, Programm 05
NumCB := 5   ; <<<<<<<<<<
 
   Loop, %NumCB%
     {
      GuiControlGet, AktCheckBoxStatus ,, % Format("CB{:02}", A_Index)
      CheckBoxColor(AktCheckBoxStatus, Format("CB{:02}", A_Index))
    }


Gui, Add, Button,     xm y150 w80      gCheckUncheck       , Alle   ; <<<<<<<<<<
Gui, Add, Button,   x110 y150 w80 Default, OK

Gui, Show, x1100 y110 Autosize, Startprogramme auswählen
WinSet, AlwaysOnTop, on		  , Startprogramme auswählen
Return

Check:
	GuiControlGet, CBID, Focus          								; IDs control clicked
	GuiControlGet, Status,, %CBID%										; Erkenne Status
	CheckBoxColor(Status, CBID)       									; Setze neuen Font
Return

CheckUncheck:
   GuiControlGet, Action, , %A_GuiControl%   ; liest die Beschriftung des Buttons
   If (Action = "Alle") {
      GuiControl, , %A_GuiControl%, Keine    ; ändert die Beschriftung des Buttons
      Check := 1                             ; alle 'checken'
   }
   Else {
      GuiControl, , %A_GuiControl%, Alle
      Check := 0                             ; alle 'unchecken'
   }

   Loop, %NumCB%
     {
      GuiControl, , % Format("CB{:02}", A_Index), %Check%
      CheckBoxColor(Check, Format("CB{:02}", A_Index))
    }
Return

ButtonOK:
	Gui, Submit															; Speichert die Inhalte der Steuerelemente in ihre zugeordneten Variablen.
	If CB01
		MsgBox, Programm 01 starten
	If CB02
		MsgBox, Programm 02 starten
	If CB03
		MsgBox, Programm 03 starten
	If CB04
		MsgBox, Programm 04 starten
	If CB05
		MsgBox, Programm 05 starten
	Goto GuiClose
Return

CheckBoxColor(State, ChkBox)
{
	Gui, Font, % State = 0 ? "c7F7F7F Norm"								; Checkbox nicht angehakt
			   : State = 1 ? "cBlack Norm"								; Checkbox angehakt
			   :			 "cDefault"
	GuiControl, Font, %ChkBox%
}

GuiEscape:
GuiClose:
Gui, Destroy
ExitApp
User avatar
LuckyJoe
Posts: 341
Joined: 02 Oct 2013, 09:52

Re: Alle Checkboxen "ankreuzen"

03 Jan 2021, 11:32

Hallo KHA,

... ja genau so, läuft super - Danke.
Herzliche Grüße aus dem Rheinland
Lucky Joe

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: No registered users and 52 guests