How do I get the Enabled
state in AutoIt of a button (either it's disabled/dimmed or enabled)? It does work for property Text
, but it seems not to work (always the same result no matter the button's state) for property Enabled
("properties" as in the .NET Windows Forms sense in Visual Studio).
This for a .NET application (Windows Forms, VB.NET) where the name of the button in the Visual Studio designer is btnStoreInModule
and property text is S&tore in Module
. The property Enabled
is what I am interested in. The button is of type System.Windows.Forms.Button
. My AutoIt script presses the button like this:
ControlClick("My Application", "", "[NAME:btnStoreInModule]")
The application responds by disabling the button while it is doing an operation. When the operation finished, the button is enabled again (undimmed). The application when the Store
button is disabled:
AutoIt Window Information Tool gives the same result for both the disabled- and the enabled state:
>>>> Window <<<<
Title: My Application 1.2a6
Class: WindowsForms10.Window.8.app.0.b7ab7b
Position: -4, 34
Size: 1448, 870
Style: 0x17CF0000
ExStyle: 0x00050100
Handle: 0x000C08DE
>>>> Control <<<<
Class: WindowsForms10.BUTTON.app.0.b7ab7b
Instance: 21
ClassnameNN: WindowsForms10.BUTTON.app.0.b7ab7b21
Name: btnStoreInModule
Advanced (Class): [NAME:btnStoreInModule]
ID: 592026
Text: S&tore in Module
Position: 257, 675
Size: 91, 23
ControlClick Coords: 59, 8
Style: 0x5601000B
ExStyle: 0x00000000
Handle: 0x0009089A
I can get the text of a TextBox control using (TB_Type
is the name of the text box in Visual Studio's property window (property "Name")):
Local $sText = ControlGetText ("My Application", "", "[NAME:TB_Type]")
For the button the corresponding line returns S&tore in Module
(as one might expect).
AutoIt version: 3.3.8.1 (2012-01-29).
Use the ControlCommand function like this:
$isControlEnabled = ControlCommand($hWin, "", "[NAME:button2]", "IsEnabled", "")
The function will return => 1 if "[NAME:button2]"
is enabled and 0 if it is disabled.
The following code should work:
Local $isControlEnabled = ControlCommand("My Application 1.2a6", "", "WindowsForms10.BUTTON.app.0.b7ab7b21", "IsEnabled")
ConsoleWrite($isControlEnabled)
The function will return 1 if the button is Enabled and 0 if it is Disabled.
User contributions licensed under CC BY-SA 3.0