首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何跟踪按钮按下情况

如何跟踪按钮按下情况
EN

Stack Overflow用户
提问于 2021-10-24 14:51:39
回答 1查看 33关注 0票数 0

我是一个建筑物的电力外壳形式,触发继电器开关,并想要保持跟踪哪些按钮被使用,并多次按下每个按钮。

EN

回答 1

Stack Overflow用户

发布于 2021-10-24 15:14:10

您需要将事件操作块附加到按钮的Click事件,在那里递增您的计数器:

代码语言:javascript
复制
# Create a hashtable to store the button counters at the start of the script
$buttonClickCounters = @{}

# define form components here etc...

# Assuming $button1 contains a System.Windows.Forms.Button:
$button1.add_Click({
  # someone clicked the button, increment counter
  $buttonClickCounters['button1']++

  # implement whatever the button is actually supposed to affect down here
})

表单运行后,您可以通过检查存储在哈希表中的值来检查单个按钮的点击次数:

代码语言:javascript
复制
$buttonClickCounters['button1'] -as [int] # this expression will now resolve to the number of times the first button was clicked
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69697903

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档