【问题标题】:Read the 'Enabled' state of a button读取按钮的“启用”状态
【发布时间】:2012-12-01 08:45:45
【问题描述】:

如何在按钮的AutoIt 中获得Enabled 状态(禁用/变暗或启用)?它确实适用于属性Text,但它似乎不适用于属性Enabled(“属性”为在 Visual Studio 中的 .NET Windows 窗体意义上)。

这适用于 .NET 应用程序(Windows 窗体、VB.NET),其中 Visual Studio 设计器中的按钮名称为 btnStoreInModule,属性文本为 S&tore in Module。属性Enabled 是我感兴趣的。按钮的类型是System.Windows.Forms.Button。我的 AutoIt 脚本按下按钮是这样的:

ControlClick("My Application", "", "[NAME:btnStoreInModule]")

应用程序通过在执行操作时禁用按钮来响应。操作完成后,按钮再次启用(未变暗)。 Store按钮被禁用时的应用:

AutoIt Window Information Tool 在禁用和启用状态下给出相同的结果:

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

可以使用(TB_Type 是 Visual Studio 属性窗口中文本框的名称(属性 "Name"))获取 TextBox 控件的文本:

Local $sText = ControlGetText ("My Application", "", "[NAME:TB_Type]")

对于按钮,相应的行返回S&amp;tore in Module(正如人们所期望的那样)。

AutoIt 版本:3.3.8.1 (2012-01-29)。

【问题讨论】:

  • 我怀疑 AutoIt 中存在错误(用于读取启用状态)。
  • 注意:在 AutoIt 中使用与 Windows Forms 相同的名称引用用户界面元素可以正常工作(我认为 AutoIt 支持 .NET)。示例:Visual Studio 设计器中的“btnStoreInModule”,该 Windows 窗体应用程序打开(实际代码是 Me.btnStoreInModules.Name = "btnStoreInModules")和 AutoIt 中的“[NAME:btnStoreInModule]”(是的,括号是 AutoIt 规范的一部分)。跨度>
  • 没有必要使用不稳定的名称(每次构建时更改),例如 WindowsForms10.BUTTON.app.0.b7ab7b21
  • 明确地说,它应该根据文档工作,但似乎没有(至少在那个版本的 AutoIt 中没有)。 AutoIt 中通常不会修复长期存在的错误,因此它可能仍然是问题,也可能不是问题。

标签: .net winforms button autoit


【解决方案1】:

像这样使用ControlCommand 函数:

    $isControlEnabled = ControlCommand($hWin, "", "[NAME:button2]", "IsEnabled", "")

如果启用"[NAME:button2]",该函数将返回=> 1,如果禁用则返回0。

【讨论】:

  • “button2”不应该是“btnStoreInModule”吗?
  • 按钮没有名称。它们有文本(“St&ore in Module”),在对话框中使用时它们可能有一个控件 ID。哪个最好,使用 Spy++ (et al) 查看 ID。
  • @Hans Passant:按钮在 AutoIt 上下文中确实有名称(我在 AutoIt 脚本中调用 ControlGetHandle()、ControlClick() 等时使用它们 - 尽管键盘快捷键通常更可靠,因为到窗口/对话框)。我可以使用名称获取“文本”属性,但不能使用 Enabled 属性。
【解决方案2】:

以下代码应该可以工作:

Local $isControlEnabled = ControlCommand("My Application 1.2a6", "", "WindowsForms10.BUTTON.app.0.b7ab7b21", "IsEnabled")
ConsoleWrite($isControlEnabled)

如果按钮启用,该函数将返回 1,如果禁用,则返回 0。

【讨论】:

  • 重新“应该工作”?你测试了吗?你用的是什么版本的 AutoIt?我怀疑 AutoIt 中存在错误(至少在该版本的 AutoIt 中),并且 ID 表单可能会或可能不会产生影响。
猜你喜欢
  • 1970-01-01
  • 2013-01-07
  • 2013-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多