问题
The below one is my program. Here my intention is to display the three CheckBoxes after the user presses the Button. They do appear after clicking the ok
-Button, but I'm unable to click on the CheckBoxes. What could be the reason?
#include <GUIConstants.au3>
$gui = GuiCreate("Hello World", 700, 600)
$Label_HelloWorld = GuiCtrlCreateLabel("Path", 40, 20, 300, 600)
$Button_OK = GuiCtrlCreateButton("OK", 450, 20, 50, 20)
GuiSetState(@SW_SHOW, $gui)
While True
$guimsg = GuiGetMsg()
Select
Case $guimsg == $GUI_EVENT_CLOSE
GuiDelete($gui)
ExitLoop
Case $guimsg == $Button_OK
$Label_sub_folder1 = GuiCtrlCreateLabel("Select the subfolder", 40, 65, 300, 600)
$CheckBox1 = GUICtrlCreateCheckbox('functionality', 40, 85, 80, 23)
$CheckBox2 = GUICtrlCreateCheckbox('performance', 160, 85, 80, 23)
$CheckBox3 = GUICtrlCreateCheckbox('listening', 280, 85, 80, 23)
Sleep(50000)
ExitLoop
EndSelect
WEnd
回答1:
The problem is that the label is a lot larger than it needs to be (600px tall), and is covering up the checkboxes. To fix just change the height to a more reasonable value (I usually use 18px for single line labels).
As an extra note, you shouldn't sleep inside a message loop. The messages will just queue up and the GUI will not be responsive. Instead you should have a timer that can run in the background.
回答2:
Your code style is a mess... Let's look at this code:
#include <GUIConstants.au3>
$gui = GUICreate("Test")
$button = GUICtrlCreateButton("ok", 200, 10, 40, 23)
$checkbox = GUICtrlCreateCheckbox("checkbox1", 10, 10, 80, 23)
GUICtrlSetState($checkbox, $GUI_HIDE)
GUISetState(@SW_SHOW)
While True
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $button
GUICtrlSetState($checkbox, $GUI_SHOW)
EndSwitch
WEnd
Where's the difference? Its label size isn't way too big in height. And it's defining every needed control element before showing the GUI. And just the elements you want to be shown later are first hidden and then shown...
So your main problem is your label height in both statements, which will create a label that covers all of your following GUI elements making them unusable. You can - if you need to - use GUICtrlSetState($background, $GUI_DISABLE)
with some kind of $background
-component like a label or a graphics to prevent it from staying at top and hindering other GUI elements to work properly.
来源:https://stackoverflow.com/questions/17403853/unable-to-click-on-the-checkbox-in-autoit