Powershell 在自定义按钮类上使用父事件
我想创建一个带有可点击按钮的GUI。我已经在程序中开始了,但我想在object中继续。所以我重新开始了我的项目。 现在,我有点被事件缠住了,尤其是添加点击 这是我的自定义按钮类Powershell 在自定义按钮类上使用父事件,powershell,oop,events,Powershell,Oop,Events,我想创建一个带有可点击按钮的GUI。我已经在程序中开始了,但我想在object中继续。所以我重新开始了我的项目。 现在,我有点被事件缠住了,尤其是添加点击 这是我的自定义按钮类 class ConfigButton : Windows.Forms.Button { # Constructor ConfigButton ([String]$Label, [int] $PosX, [int] $PosY) { # Set properties
class ConfigButton : Windows.Forms.Button {
# Constructor
ConfigButton ([String]$Label, [int] $PosX, [int] $PosY) {
# Set properties
$this.Text = $Label
$this.Location = New-Object System.Drawing.Point($PosX,$PosY)
$this.Autosize = $True
}
# Functions
[void] AddToWindow([ConfigWindow]$Window) {
$Window.Controls.Add($this)
}
[String] ToString() {
return $this.Text
}
#Events
}
我的问题是:如何在我的自定义类中添加添加单击事件?
我天真地尝试了$this.Add\u单击,但没有
这是我的“Main”,我在这里创建我的对象并将其添加到我的主窗口(原始值在这里用于测试)
谢谢。你不需要添加它-它已经在那里了,从按钮继承而来。
:)只需执行$ButtonClose。添加({})
这就是我最后做的。这不是我想做的,但似乎我别无选择。
$Main = New-Object ConfigWindow("Main Window", 1000, 800)
$ButtonClose = New-Object ConfigButton("Fermer",200, 200)
$ButtonClose.AddToWindow($Main)
Write-Host $ButtonClose.ToString()
$Main.DisplayWindow()