Jump to content

need help with checkboxes


Recommended Posts

I'm writing a GUI now and now i don't know how to get further. I have my GUI in OnEvent mode (that must stay like this) and now i want to make a checkbox, that when you disable it, that some inputs will be greyed out, and when you enable it they will be availeble again. I just can't get it to work, i really don't know what to do.

Here is some of the code, please tell me what i must do:

$temp_login = GUICtrlCreateCheckbox("Server vereist login", 115, 79)
If IniRead(@ScriptDir & "\POWRPOST.INI", "Settings", "Login", "NotFound") = 0 Then
    GUICtrlSetState($temp_login, $GUI_UNCHECKED)
Else
    GUICtrlSetState($temp_login, $GUI_CHECKED)
EndIf

$temp_login = GUICtrlRead($temp_login)

GUICtrlCreateLabel("Gebruikersnaam:", 20, 102)

$temp_gebruikersnaam = IniRead(@ScriptDir & "\POWRPOST.INI", "Settings", "User", "NotFound")

If IniRead(@ScriptDir & "\POWRPOST.INI", "Settings", "Login", "NotFound") = 0 Then
    $gebruikersnaam = GUICtrlCreateInput("gast", 115, 100, 200, 20)
    If $temp_login = $GUI_CHECKED Then
        GUICtrlSetState($gebruikersnaam, $GUI_ENABLE)
    ElseIf $temp_login = $GUI_UNCHECKED Then
        GUICtrlSetState($gebruikersnaam, $GUI_DISABLE)
    EndIf
Else
    $gebruikersnaam = GUICtrlCreateInput($temp_gebruikersnaam, 115, 100, 200, 20)
    If $temp_login = $GUI_CHECKED Then
        GUICtrlSetState($gebruikersnaam, $GUI_ENABLE)
    ElseIf $temp_login = $GUI_UNCHECKED Then
        GUICtrlSetState($gebruikersnaam, $GUI_DISABLE)
    EndIf
EndIf

I think i should place something in the While loop (there's only sleep(10) now) but i don't know what.

Link to comment
Share on other sites

You need to set an GuiCtrlSetOnEvent for the checkbox and function it will call

also becareful, you overwrote the controlId for the checkbox, i commented that line out.

for example (didn't test this out, but should do it)

$temp_login = GUICtrlCreateCheckbox("Server vereist login", 115, 79)
GUICtrlSetOnEvent(-1, "_SetControlsState")
If IniRead(@ScriptDir & "\POWRPOST.INI", "Settings", "Login", "NotFound") = 0 Then
    GUICtrlSetState($temp_login, $GUI_UNCHECKED)
Else
    GUICtrlSetState($temp_login, $GUI_CHECKED)
EndIf

;~ $temp_login = GUICtrlRead($temp_login)

GUICtrlCreateLabel("Gebruikersnaam:", 20, 102)

$temp_gebruikersnaam = IniRead(@ScriptDir & "\POWRPOST.INI", "Settings", "User", "NotFound")

If IniRead(@ScriptDir & "\POWRPOST.INI", "Settings", "Login", "NotFound") = 0 Then
    $gebruikersnaam = GUICtrlCreateInput("gast", 115, 100, 200, 20)
    If GUICtrlRead($temp_login) = $GUI_CHECKED Then
        GUICtrlSetState($gebruikersnaam, $GUI_ENABLE)
    ElseIf GUICtrlRead($temp_login) = $GUI_UNCHECKED Then
        GUICtrlSetState($gebruikersnaam, $GUI_DISABLE)
    EndIf
Else
    $gebruikersnaam = GUICtrlCreateInput($temp_gebruikersnaam, 115, 100, 200, 20)
    If GUICtrlRead($temp_login) = $GUI_CHECKED Then
        GUICtrlSetState($gebruikersnaam, $GUI_ENABLE)
    ElseIf GUICtrlRead($temp_login) = $GUI_UNCHECKED Then
        GUICtrlSetState($gebruikersnaam, $GUI_DISABLE)
    EndIf
EndIf

Func _SetControlsState()
    If GUICtrlRead($temp_login) = $GUI_CHECKED Then
        GUICtrlSetState($gebruikersnaam, $GUI_ENABLE)
    Else
        GUICtrlSetState($gebruikersnaam, $GUI_DISABLE)
    EndIf
EndFunc  ;==>_SetControlsState

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

That works, but not totally 100%, cause where this all hapened was an settings window, but when I press Save, i go back to the main window and when i then press Settings, the input will stay greyed out and all settings are written as 0 in the INI file. You know a solution?

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