我是一个建筑物的电力外壳形式,触发继电器开关,并想要保持跟踪哪些按钮被使用,并多次按下每个按钮。
发布于 2021-10-24 15:14:10
您需要将事件操作块附加到按钮的Click事件,在那里递增您的计数器:
# 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
})表单运行后,您可以通过检查存储在哈希表中的值来检查单个按钮的点击次数:
$buttonClickCounters['button1'] -as [int] # this expression will now resolve to the number of times the first button was clickedhttps://stackoverflow.com/questions/69697903
复制相似问题